MATLAB - random allocation of random number

AI Thread Summary
To generate a random number (0 or 1) and allocate it to one of 100 groups in MATLAB, use the `randint(1)` function for the random number generation. To allocate this number to a group, implement a for loop with a pre-allocated array, ensuring to generate random positions within the array for each allocation. It's important to set the upper bound to 100 and manage the allocation to avoid duplicates. This process can be repeated a million times to achieve the desired outcome. Properly structuring the code will ensure efficient execution of the random allocation task.
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.
 
Back
Top