Contenuto principale

reset

R2026b

Reset random number stream

Description

reset(s) resets the random number stream s to the initial internal state associated with the seed of the stream. The reset function restores the State property of s without changing other properties, such as Seed, NormalTransform, Antithetic, or FullPrecision.

example

reset(s,seed) resets the random number stream s to the initial internal state associated with the specified seed value and updates the Seed property of s. The value of seed must be an integer between 0 and 232 − 1. Resetting the seed of a stream can invalidate independence with other streams.

Note

Reset a stream only when you want to reproduce results from the stream.

example

Examples

collapse all

Create a random number stream with a seed of 3 that uses the inversion normal transformation algorithm. Use the stream to generate five normally distributed random numbers.

stream = RandStream("dsfmt19937",Seed=3,NormalTransform="Inversion")
stream = 

dsfmt19937 random stream
             Seed: 3
  NormalTransform: Inversion
r = randn(stream,1,5)
r = 1×5
-0.6588	1.1519	-1.3357	-1.2039	-0.3538

Reset the random number stream to its initial state.

reset(stream)
stream
stream = 

dsfmt19937 random stream
             Seed: 3
  NormalTransform: Inversion

Reproduce the five random numbers that were generated.

r = randn(stream,1,5)
r = 1×5
-0.6588	1.1519	-1.3357	-1.2039	-0.3538

Reset a random number stream using a specific seed.

stream = RandStream("mt19937ar",Seed=0,NormalTransform="Inversion")
stream = 

mt19937ar random stream
             Seed: 0
  NormalTransform: Inversion
reset(stream,1)
stream
stream = 

mt19937ar random stream
             Seed: 1
  NormalTransform: Inversion

Input Arguments

collapse all

Random number stream, specified as a RandStream object. If you generate random numbers on a GPU, you can specify s as a parallel.gpu.RandStream (Parallel Computing Toolbox) object.

Random number generator seed, specified as a nonnegative integer. The value of seed must be an integer between 0 and 232 − 1.

Version History

Introduced in R2008b