0

I am trying to generate random integers (either 0 or 1). This code does this very well:

randi([0 1],10000,1)

The only problem is that randi obviously generates binomial distributions. I need to be able to set a weighting to these numbers. For example, I want 55% of the distribution to be 1 and the other 45% to be 0.

Is there a way to do this?

ServerS
  • 452
  • 3
  • 15
  • 2
    possible duplicate of [Weighted random numbers in MATLAB](http://stackoverflow.com/questions/2977497/weighted-random-numbers-in-matlab) – or [Generate Weighted Random Boolean Matrix in Matlab](http://stackoverflow.com/questions/18370382/generate-weighted-random-boolean-matrix-in-matlab) – horchler Aug 19 '15 at 19:19
  • 2
    Even simpler than those answers in this case: `rand(10000,1)>0.45`. – David Aug 19 '15 at 22:44

0 Answers0