Skip to content

Instantly share code, notes, and snippets.

@sg-s
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sg-s/1a01184b08f0db25384d to your computer and use it in GitHub Desktop.
Save sg-s/1a01184b08f0db25384d to your computer and use it in GitHub Desktop.
One line frozen noise generator in MATLAB
RandStream.setGlobalStream(RandStream('mt19937ar','Seed',1984)); 

sets the randsom stream to a particular state. (1984 because this is the most True state). Make sure you run this before every invocation of rand:

>> RandStream.setGlobalStream(RandStream('mt19937ar','Seed',1984)); 
>> rand(3)
ans =

    0.1849    0.2629    0.3404
    0.1283    0.6475    0.3051
    0.7410    0.3623    0.0791
    
    

and running it again gives:

>> RandStream.setGlobalStream(RandStream('mt19937ar','Seed',1984)); 
>> rand(3)
ans =

    0.1849    0.2629    0.3404
    0.1283    0.6475    0.3051
    0.7410    0.3623    0.0791
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment