MATLAB - random allocation of random number

Click For Summary
SUMMARY

This discussion focuses on generating a random number (0 or 1) in MATLAB and allocating it to one of 100 groups, repeating this process one million times. The user suggests using the randint(1) function for random number generation and emphasizes the importance of using a for loop with a pre-allocated array to efficiently manage the allocations. Additionally, it is crucial to ensure that the random positions generated for allocation do not repeat, maintaining the integrity of the group assignments.

PREREQUISITES
  • Familiarity with MATLAB programming language
  • Understanding of random number generation techniques
  • Knowledge of array manipulation in MATLAB
  • Basic concepts of loops and iterations in programming
NEXT STEPS
  • Explore MATLAB's randperm function for unique random allocations
  • Learn about pre-allocating arrays in MATLAB for performance optimization
  • Investigate MATLAB's randi function for generating random integers
  • Study techniques for handling large datasets in MATLAB efficiently
USEFUL FOR

This discussion is beneficial for MATLAB programmers, data analysts, and anyone interested in random number generation and allocation techniques within MATLAB for simulations or statistical modeling.

mathman44
Messages
204
Reaction score
0
Hi. I'm being asked to generate a random number either 0 or 1 and then to randomly allocate this 0 or 1 to one of 100 groups, and then to repeat this many (a million) times.

So... I can easily generate randomly either a 0 or 1 by randint(1), but how do I randomly allocate this to 1 of 100 "groups" (one row of a column vector, for example)? And then how do I repeat this process a million times?

Any help would be greatly appreciated.
 
Last edited:
Physics news on Phys.org
What you can do is use a for loop with a pre-allocated array. Then you would have to randomly generate positions within the array to place your variable. You would have to place your upper bound as 100 and careful not to repeat any allocations.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
Replies
1
Views
3K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
Replies
20
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 23 ·
Replies
23
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K