fpe
fpe

Reputation: 2750

Random number - Choose seed

because of one project I have to make use of pseudo random numbers with normal distribution.

To this respect, I'm generally putting this down:

nn_u = complex((normrnd(0,1.0,size(H_u))),(normrnd(0,1.0,size(H_u))));
nn_v = complex((normrnd(0,1.0,size(H_u))),(normrnd(0,1.0,size(H_u))));
nn_w = complex((normrnd(0,1.0,size(H_u))),(normrnd(0,1.0,size(H_u))));
size(H_u) = [4096,1];

This way I don't have any real access to the seed number. What I expect is that, using the above mentioned form, there will be 6 seeds, that means one different seed for any of the six times called normrnd function.

What I'd like to do at the moment is to generate six independent representations, just as happens above, with only one seed point, which I can pick out of the range [1,999].

To achieve this I was thinking to proceed this way:

n = 4096;
nn_tmp = normrnd(0,1,[n*6,1]);
nn_u = complex(nn_tmp(1:n,1),nn_tmp(n+1:2*n,1));
nn_v = complex(nn_tmp(2*n+1:3*n,1),nn_tmp(3*n+1:4*n,1));
nn_w = complex(nn_tmp(4*n+1:5*n,1),nn_tmp(5*n+1:6*n,1));

But this way, I don't have any direct access to the seed; I don't even know if the kind of operation I'd do has any strong theoretical validation.

Any support would be welcome.

Upvotes: 0

Views: 777

Answers (1)

Dan
Dan

Reputation: 45741

I think you can use rng to seed and then use randn instead of normrnd for your problem

So something like

SEED = 120; %for example
rng(SEED, 'twister');
nn_u = complex(randn(size(H_u)),randn(size(H_u)));
nn_v = complex(randn(size(H_u)),randn(size(H_u)));
nn_w = complex(randn(size(H_u)),randn(size(H_u)));

Upvotes: 2

Related Questions