How to know seed directly?

17 Ansichten (letzte 30 Tage)
Hsinho
Hsinho am 8 Aug. 2012
Hi,
I use "rng" to know which seed was selected after doing "rng shuffle."
How can I only know the seed directly? I don't need to know "type" and "state."
Thanks!

Akzeptierte Antwort

Peter Perkins
Peter Perkins am 8 Aug. 2012
Hsinho, you may be asking for this:
>> rng shuffle
>> s = rng
s =
Type: 'twister'
Seed: 1066045100
State: [625x1 uint32]
>> s.Seed
ans =
1066045100
  3 Kommentare
Peter Perkins
Peter Perkins am 9 Aug. 2012
Bearbeitet: Peter Perkins am 9 Aug. 2012
1) You are calling rng in a loop. Unless you are doing something specialized, you almost certainly do not need to do that. It may be that you want some kind of reproducibility for each individual iteration of the loop. I strongly recommend that you read the documentation about how to use rng. If that kind of reproducibility is what you are after, especially read the last paragraph, and then perhaps also read this description of substreams etc. But chances are, you do not want to call rng in a loop.
2) s{i}.State
Hsinho
Hsinho am 9 Aug. 2012
Thank you! It's very helpful.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Greg Heath
Greg Heath am 8 Aug. 2012
Bearbeitet: Greg Heath am 8 Aug. 2012
I think it is better to determine the seed before you generate the random numbers. In particular,
Either assign the seed first or determine the current seed before using shuffle.
If you know that you are going to use random numbers, it is convenient to set the seed at the beginning of the program when space and figures are cleared. For example:
close all; clear all; clc;
plt = 0; rng(4151941);
. . .
plt = plt+1; figure(plt);
. . .
Hope this helps.
Greg
  1 Kommentar
Hsinho
Hsinho am 9 Aug. 2012
Thanks for your answer!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by