How to efficiently create a matrix of random numbers generating independently?

1 回表示 (過去 30 日間)
Hsinho
Hsinho 2012 年 7 月 1 日
Hi,
I want to have a 100-by-2000 matrix of random numbers. Each column of random numbers is generated by an independent stream. It means there should be 2000 independent streams.
I learn from "Help: Create three independent streams"
[s1,s2,s3] = RandStream.create('mrg32k3a','NumStreams',3);
r1 = rand(s1,100000,1); r2 = rand(s2,100000,1); r3 = rand(s3,100000,1);
It is very easy with 3 independent streams.
How can I efficiently create this matrix of random numbers from 2000 independent streams?
Thank you!
  3 件のコメント
Richard Brown
Richard Brown 2012 年 7 月 2 日
+1 Jan
Hsinho
Hsinho 2012 年 7 月 2 日
編集済み: Walter Roberson 2012 年 7 月 2 日
My first attempt to generate the 100-by-2000 matrix with random numbers is simply using "rand" or "randi."
The three main steps involving random numbers generation in the script are as followed.
len=100;
R=2000;
y=zeros(len,R);
for n=1:2.1e7
N=(0:len:(R-1)*len)+randi(len,1,R); % Only one element in each column was randomly selected.
y(N)=-1+9*rand(1,R); % The selected element of y matrix was replaced with a random number uniformly distributed from -1 to 8.
A=find(deltaE>0); %Compare E values calculated from y values in each column
exp(-delta_E/k/T)>rand(1,length(A)); %Accept E values when it meets the criterion.
end
When this for-loop finished, I observed clearly that the y values in the last 200 to 500 columns fluctuated around zero or still are zero but the all other y values from column 1 to column 1500 vary between -1 and 8.
I don't understand why this happen. I expected all columns should vary between -1 and 8.
The goal I want to reach is that all the random number generating(random N, random y values, rand(1,length(A)) in each column is independent to each other. The calculation of E value in each column is a independent simulation (i.e. I want to do 2000 independent simulations simultaneously).
However,the present results I have is that some columns seems untouched.
How can I modify the script to accomplish my goal?
Thanks !

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

回答 (0 件)

カテゴリ

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