rng_seed

Seed the Matlab default (global) random number generator

Syntax

   state = rng_seed(seed)

Arguments

input

   seed       random seed: an integer in the range [0, 2^32 ? 1], or a negative number

output

   state      previous rng state

Description

Seed the Matlab default (global) random number generator (which is used for calls such as rand, randn, etc.). If seed is positive, use that seed. If zero, do nothing. If negative, seed with something really unpredictable, using either get_urand (Unix, Mac) or get_crand (Windows); see e.g. the MVGC startup script. Optionally return the previous rng state in state (see rng_restore).

Example

   state = rng_seed(seed);
   X = rand(10,3);
   rng_restore(state);

See also

rng | rng_save | rng_restore | get_urand | get_crand | startup