MATLAB - random allocation of random number

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 4K views
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.