Two input numbers random generation

1 view (last 30 days)
How can I randomly generate just two input numbers, for example: 1 or 3; 0.95 or 1.05 ?
  1 Comment
Stephen23 on 6 Dec 2015
What range? What distribution? What precision?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 6 Dec 2015
If you are trying to randomly generate from a set of distinct numbers, then you can use randsample() if you have the Statistics Toolbox. If you do not then see the File Exchange such as
In the simplest form of equal weight, to draw N times from two values stored in Samples,
Samples( 1 + (rand(1,N) > 1/2) )
  1 Comment
Nikolay Panasetsky
Nikolay Panasetsky on 6 Dec 2015
Thank you so much) You helped me out again

Sign in to comment.

More Answers (0)


Find more on Random Number Generation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!