New Random Number Suite in GAUSS 12
Parallel Random Number Generation:
GAUSS 12 offers two methods for parallel random number generation, through the use of multiple streams or with block-skipping.
Multiple Streams
Most random number generators will produce a sequence of random numbers that is equal to their period length. However some random number generators, such as the Mersenne-Twister 2203 include in GAUSS 12, can create more than one substream of random numbers equal in length to their full period.
To take advantage of this feature, you need to create a state from the desired substream with the function rndCreateState and pass it in to the random number generating function of your choice.
// Create a state from the 103rd and 219th substream// of the Mersenne-Twister 2203 RNG
seed = 83934003;
state1 = rndCreateState( "mt2203-103", seed );
state2 = rndCreateState( "mt2203-219", seed );
// Create a 5x5 random normal matrix with each of these
// respective state vectors.
{ x, state1 } = rndn( 5, 5, state1 );
{ y, state2 } = rndn( 5, 5, state2 );
The random numbers from these newly created state vectors will allow the creation of independent streams of random numbers that may be safely passed into multithreaded code.
Block Skipping
Block skipping allows you to advance a random number stream a specified number of values without calculating them. As a simple example, we will create a random number state vector and then skip it forward by two numbers.
// Create a state using the MRG32k3a generatorseed = 6354123452;
state = rndCreateState( "mrg32k3a", seed );
// Create a new state that will skip ahead two numbers
statePlusTwo = rndStateSkip( 2, state );
{ r, state } = rndn( 4, 1, state );
{ r2, statePlusTwo } = rndn( 2, 1, statePlusTwo );
print r;
1.1957677
0.14053340
-0.16571487
0.22579434
print r2;
-0.16571487
0.22579434
Option for simple syntax and no need for code change
While the options for creating parallel, threadsafe random number calls are available, you are not required to pass in a state vector, or to change your code in any way. The new random number functions all allow you to pass in and return the state vector as an optional argument. For more complex programs you may use any of the methods from above. However, for simpler programs or initial prototyping you are not required to use or create a state vector.
r = rndn( rows, cols );In these cases, simple syntax as shown above can be used for any of the new random number functions.