フィルターのクリア

Generation of a pair of random numbers satisfying a constraint

3 ビュー (過去 30 日間)
Shah Muhammad
Shah Muhammad 2021 年 7 月 6 日
回答済み: Stephan 2021 年 7 月 6 日
Hi, guys, I want to generate s sequence of two random numbers r1 and r2 satisfying the condition 0<r1<r2<1. How to do it using MATLAB. Your response is highly appreciated. Thank you!
Shah
  1 件のコメント
Johannes Hougaard
Johannes Hougaard 2021 年 7 月 6 日
The easy way...but that also yields r1 < .5 and r2 > .5 is:
N = 99; % Or any other number but 99 is my go-to number of observations
r1 = rand(N,1)*.5;
r2 = randn(N,1)*.5 + .5;

サインインしてコメントする。

採用された回答

Stephan
Stephan 2021 年 7 月 6 日
N = 10;
r = sort(rand(N,2),2)
r = 10×2
0.0901 0.9582 0.2136 0.7758 0.7603 0.9945 0.0893 0.8684 0.2264 0.4635 0.2086 0.7458 0.6878 0.9048 0.3360 0.7293 0.2467 0.6758 0.2907 0.5876

その他の回答 (1 件)

KSSV
KSSV 2021 年 7 月 6 日
A = sort(rand(1,2))
A = 1×2
0.0481 0.4146

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by