how to get non-repeatable randn results?

Hello,
I tried use rng('shuffle') to avoid repeatable random normal-distribution matrix. However, I used 3 computers to run the same simulation with random terms, and I got the exactly same results.
Any other way to avoid repeating the same random number arrays?
Thanks

2 Comments

I get different results every time with randn
Wei
how do you exactly use nrg?
1.
If you put a numeric value in rng, the randomly generator is the same:
rng(24);randn(3)
=
1.0885 1.0189 -0.8340
0.2399 1.4842 -0.3819
-0.4323 -0.6442 -0.1571
>> rng(24);randn(3)
=
1.0885 1.0189 -0.8340
0.2399 1.4842 -0.3819
-0.4323 -0.6442 -0.1571
with shuffle the result is different, isn't it?
rng('shuffle');randn(3)
=
-0.0854 0.2199 0.6849
0.6600 -0.1634 0.7637
0.8772 -1.4346 -0.4255
rng('shuffle');randn(3)
=
0.1883 1.7646 -0.0552
0.1572 1.4956 -0.2677
-0.7904 -1.5864 -0.3946
John BG

Sign in to comment.

Answers (1)

Jan
Jan on 14 Mar 2017
Edited: Jan on 14 Mar 2017
According to doc rng:
rng('shuffle') seeds the random number generator based on the current time.
If you start the program on all computers exactly at the same time, you will get the same results. This is rather unlikely, but possible. You can avoid this by using seeds, which depend on the individual computer. Unfortunately I do not find in the docs currently, which or how many bits of the seeds are considered. If you can assign each computer a unique number, rng(1) etc. might be sufficient. But if you cannot "tag" the computers, the problem is not trivial.
@Readers: What is the valid input range for the seeds?
[EDITED] A guess (I'll test this later):
UID = char(java.util.UUID.randomUUID);
Num = uint8(sscanf(UID(UID ~= '-'), '%2x'));
% 64 random bits (must be provided as UINT64)
Seed = typecast(Num(1:8), 'uint64');
% Or 32 random bits:
Seed = double(typecast(Num(1:4), 'uint32'));
% Or a double with 53 random bits (0 <= Seed < 1):
Tmp = double(typecast(Num(1:8), 'uint32'));
Seed = (Tmp(1) * 2097152 + Tmp(2) / 2048) / 9007199254740992.0;
The Mersenne Twister needs 624 * 32 bits for an exhaustive seeding actually.

1 Comment

Seeds are from 0 to 2^32-1. But if you're really doing parallel simulations, you should consider using parallel generators .

Sign in to comment.

Categories

Tags

Asked:

on 14 Mar 2017

Commented:

on 15 Mar 2017

Community Treasure Hunt

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

Start Hunting!