How to make a random number generator in matlab that is based on percentages?

Posted by Ben Fossen on Stack Overflow See other posts from Stack Overflow or by Ben Fossen
Published on 2010-05-19T06:27:19Z Indexed on 2010/05/19 6:30 UTC
Read the original article Hit count: 213

I am currently using the built in random number generator.

for example

nAsp = randi([512, 768],[1,1]);

512 is the lower bound and 768 is the upper bound, the random number generator chooses a number from between these two values.

What I want is to have two ranges for nAsp but I want one of them to get called 25% of the time and the other 75% of the time. Then gets plugged into he equation. Does anyone have any ideas how to do this or if there is a built in function in matlab already?

for example

nAsp = randi([512, 768],[1,1]); gets called 25% of the time

nAsp = randi([690, 720],[1,1]); gets called 75% of the time

© Stack Overflow or respective owner

Related posts about matlab

Related posts about random-number-generator