Re: Problem with 'Random' function



"Nitin Chhabra" <nitin.chhabra@xxxxxx> writes:

Peter Perkins <Peter.PerkinsRemoveThis@xxxxxxxxxxxxx> wrote
in message <g4taf9$mpj$1@xxxxxxxxxxxxxxxxxx>...
Nitin Chhabra wrote:

Here is the output when i write "help randperm" :

help randperm

RANDPERM Random permutation.
RANDPERM(n) is a random permutation of the integers
from 1 to n.
For example, RANDPERM(6) might be [2 4 5 6 1 3].

Note that RANDPERM calls RAND and therefore changes
RAND's state.

See also PERMUTE.

So if I am wrong then help should be modified accordingly. Because
that also writes the same as i stated.

Nitin, there's a big difference between what the help above says, and
explicitly resetting the state of the random number generator before
each call to RAND. There is no good reason that I know of to do the
latter, and in fact, depending on how you do it, doing that could
introduce non- randomness in the output.

Resetting the random number generator is something you
should do

1) (perhaps) once at startup, to get different sequences of values in
different matlab sessions, or

2) to reproduce results for testing or debugging purposes.


Hi Peter,

I think I have confused the thing.Let me clarify it :

What I intended was not to reset the state of random number
generator. But to set the state each time to a value
different from the previous value just to make sure random
number generated is not repeated.

Nitin-

I mean no offense, but you should probably read up on how pseudorandom
number generators work. Here's a primer:

http://en.wikipedia.org/wiki/Pseudorandom_number_generator

Pay special attention to the section on periodicity.

A PRNG generates a sequence of numbers which appear random. The
periodicity is how long that sequence is before it repeats. MATLAB's
Mersenne Twister algorithm generates a VERY long sequence before it
repeats. This is different from repeating one sample, which must be
able to happen if you want independent random samples.

The "seed" of a random number generator can be thought of as an index
into the huge sequence of numbers. And manually setting the seed in
between each sample makes the numbers far less random (you are basically
defeating the entire design of the PRNG). Nor does it prevent repeated
samples.

When RANDPERM says "changes the RAND's state", the point is that it uses
RAND to generate it's random numbers, which advances RAND's PRNG one
sample, which changes the state. The state changes every time you draw
a sample.

Still, you should only ever set the state of a PRNG manually ONCE, at
the beginning of each experiment, for either of two reasons: You want
the PRNG to give you the same sequence each time. Or you want the PRNG
to give you a different sequence each time. After that, let the PRNG do
it's job.

-Peter
.



Relevant Pages

  • Re: PRNG
    ... that is a non periodic Pseudo Random Number Generator. ... so large that for all practical purposes it never repeats, ... Generator algorithm on a computer that lacks infinite memory. ... A cryptographically secure prng is quite an achievement. ...
    (sci.crypt)
  • Re: Whats wrong with this code snippet?
    ... I don't think you want to seed your PRNG ... >Yes, it is random module. ... time to seed the generator. ... proding a new, different sequence. ...
    (comp.lang.python)
  • Re: Agduria dungeon generation
    ... sequence of numbers longer than the dimensionality of your generator. ...  But that bug mainly belongs to the PRNG, ... to the dungeon generator. ...
    (rec.games.roguelike.development)
  • Re: Agduria dungeon generation
    ... sequence of numbers longer than the dimensionality of your generator. ... But that bug mainly belongs to the PRNG, ... to the dungeon generator. ...
    (rec.games.roguelike.development)
  • Re: In Firefox (2.0.0.18) .readyState hung at 3 while .responseText has the data but .responseXML is
    ... Whether numbers can repeat would depend on the length of the sequence ... My reasoning does assume that the PRNG is used in a sensible manner. ... Obviously one *could* use a 64-bit generator and feed only 4 bits into ...
    (comp.lang.javascript)

Loading