MATLAB - random allocation of random number

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
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.