Two input numbers random generation

조회 수: 1 (최근 30일)
Nikolay Panasetsky
Nikolay Panasetsky 2015년 12월 6일
댓글: Nikolay Panasetsky 2015년 12월 6일
Hello.
How can I randomly generate just two input numbers, for example: 1 or 3; 0.95 or 1.05 ?
  댓글 수: 1
Stephen23
Stephen23 2015년 12월 6일
What range? What distribution? What precision?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2015년 12월 6일
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 http://www.mathworks.com/matlabcentral/fileexchange/21912-sampling-from-a-discrete-distribution
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
Nikolay Panasetsky
Nikolay Panasetsky 2015년 12월 6일
Thank you so much) You helped me out again

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by