Generate seed as a integer vector

generateSeedVectors(nseeds, nwords = 2L)

Arguments

nseeds

Integer scalar, number of seeds to generate.

nwords

Integer scalar, number of words to generate per seed.

Value

A list of length n, where each element is an integer vector that contains nwords words (i.e., 32*nwords bits) of randomness.

Details

Each seed is encoded as an integer vector with the most significant bits at the start of the vector. Each integer vector is converted into an unsigned integer (in C++ or otherwise) by the following procedure:

  1. Start with a sum of zero.

  2. Add the first value of the vector.

  3. Left-shift the sum by 32.

  4. Add the next value of the vector, and repeat.

The aim is to facilitate R-level generation of seeds with sufficient randomness to cover the entire state space of pseudo-random number generators that require more than the ~32 bits available in an int. It also preserves the integer nature of the seed, thus avoiding problems with casting double-precision numbers to integers.

It is possible for the seed vector to contain NA_integer_ values. This should not be cause for alarm, as R uses -INT_MAX to encode missing values in integer vectors.

Author

Aaron Lun

Examples

generateSeedVectors(10, 2)
#> [[1]]
#> [1] -711550517   31749989
#> 
#> [[2]]
#> [1] 1244576670 -538628920
#> 
#> [[3]]
#> [1] 1376020222 1733169228
#> 
#> [[4]]
#> [1]  -105035210 -1136840150
#> 
#> [[5]]
#> [1] -1110176469 -1306415035
#> 
#> [[6]]
#> [1]  968772867 2057399970
#> 
#> [[7]]
#> [1]  -220910038 -1373667404
#> 
#> [[8]]
#> [1] -1459087211  -989200993
#> 
#> [[9]]
#> [1] 1671525904  750225429
#> 
#> [[10]]
#> [1] -947899323  280124077
#> 

generateSeedVectors(5, 4)
#> [[1]]
#> [1]  1176015342 -1734070009 -1965061269  1918590747
#> 
#> [[2]]
#> [1] 2001363929 1619103574 1652721445 1122585152
#> 
#> [[3]]
#> [1]  -343578987 -1409806591   640124096 -1210040890
#> 
#> [[4]]
#> [1]  -709556440  -834547611   938175257 -2114606835
#> 
#> [[5]]
#> [1]  -706300558    49341284 -2146673691 -1784634804
#>