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

1 visualización (últimos 30 días)
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 comentarios
Hsinho
Hsinho el 2 de Jul. de 2012
Editada: Walter Roberson el 2 de Jul. de 2012
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 !

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by