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]   -88714333 -1949307540
#> 
#> [[2]]
#> [1] 1864536384 2006563359
#> 
#> [[3]]
#> [1] -1301197649   943343135
#> 
#> [[4]]
#> [1] -1434337077  1739088822
#> 
#> [[5]]
#> [1] 1827029352  722037749
#> 
#> [[6]]
#> [1] 1057380189 1354948216
#> 
#> [[7]]
#> [1]   521299698 -1081399130
#> 
#> [[8]]
#> [1] -490243503 1511651427
#> 
#> [[9]]
#> [1]  105079332 -934655227
#> 
#> [[10]]
#> [1]  -419999622 -1438611305
#> 

generateSeedVectors(5, 4)
#> [[1]]
#> [1]  2083621050   457510342 -1939744193   -19405426
#> 
#> [[2]]
#> [1]  -648561935 -2063851495  -333613475 -1402621775
#> 
#> [[3]]
#> [1]  666121927 1161334499  179633460 -385137708
#> 
#> [[4]]
#> [1] -1056703420   834917401  1256087621  1893958176
#> 
#> [[5]]
#> [1]  -706232831  1127265497 -1406016221  -358107668
#>