Random Number Generator Matlab with Multiple CPUs

后端 未结 4 642
梦如初夏
梦如初夏 2020-12-18 13:57

I would like to write a matlab script which runs in parallel using multiple CPUS. The script should then print out a sequence of normally distributed random numbers. At the

4条回答
  •  不知归路
    2020-12-18 14:28

    Reset the random number generator used by rand, randi, and randn to its default startup settings, so that rand produces the same random numbers as if you restarted MATLAB®:

    rng('default')
    rand(1,5)
    ans =
        0.8147    0.9058    0.1270    0.9134    0.6324
    

    Save the settings for the random number generator used by rand, randi, and randn, generate 5 values from rand, restore the settings, and repeat those values:

    s = rng;
    u1 = rand(1,5)
    u1 =
        0.0975    0.2785    0.5469    0.9575    0.9649
    
    rng(s);
    u2 = rand(1,5)
    u2 =
        0.0975    0.2785    0.5469    0.9575    0.9649
    

    Reinitialize the random number generator used by rand, randi, and randn with a seed based on the current time. rand returns different values each time you do this. Note that it is usually not necessary to do this more than once per MATLAB session as it may affect the statistical properties of the random numbers MATLAB produces:

    rng('shuffle');
    rand(1,5);
    

    I would try different generators:

    rng('shuffle', generator)
    

    rng('shuffle', generator) additionally specify the type of the random number generator used by rand, randi, and randn. The generator input is one of:

    'twister'       Mersenne Twister
    'combRecursive'     Combined Multiple Recursive
    'multFibonacci'     Multiplicative Lagged Fibonacci
    'v5uniform'         Legacy MATLAB® 5.0 uniform generator
    'v5normal'      Legacy MATLAB 5.0 normal generator
    'v4'                Legacy MATLAB 4.0 generator
    

提交回复
热议问题