NCL Website header
NCL Home > Documentation > Functions > Random number generators

random_setallseed

Sets initial seeds for random number generators.

Prototype

	procedure random_setallseed (
		iseed1  : integer,  
		iseed2  : integer   
	)

Arguments

iseed1

Any integer between 1 and 2,147,483,562 (default is 1234567890).

iseed2

Any integer between 1 and 2,147,483,398 (default is 123456789).

Description

This procedure is used to set the state of a random number generator. If the user does not explicitly set the seeds, they are set to the stated default values. It is recommended that the user specify these seeds. The source of this random number seed generator is from the random section at Netlib. The authors were Brian Brown and James Lovato. The official reference is:

Authors: P. L'Ecuyer and S. Cote
Title: Implementing a Random Number Package with Splitting Facilities
Journal: ACM Transactions on Mathematical Software 17:1, pp 98-111.

See Also

random_chi, random_gamma, random_normal, random_uniform

Examples

Example 1

Set seeds for generating random deviates:

  random_setallseed(136484749,19494848)      ; Set seeds (suggested, NOT required)

Example 2

One method of assuring different seeds is to use some available timing function(s). This accesses the *nix system date functions. For example: here the letter 'l' is appended to the two constants to force long integers. The mod operator, %, is used on the two long integers and the toint function forces a return to the required 32-bit integer.

    rseed1 = toint(systemfunc(" date +%s"))
    rseed2 = toint((12345l*rseed1)%2147483398l)
    random_setallseed(rseed1, rseed2)

Testing might look like:

    N     = 100
    do i = 0,999
       rand1_tst = toint(systemfunc(" date +%s"))
       rand2_tst = toint((54321l*rand1_tst)%2147483398l)
       random_setallseed(rand1_tst, rand2_tst)
       test = random_normal(0,1,N)
       print(test)
    end do