set.seed(seed, kind = NULL, normal.kind = NULL) RNGkind(kind = NULL, normal.kind = NULL) RNGversion(vstr) .Random.seed
seed | NULL or an integer value used to set the state of the random uniform generator. Each random uniform generator interprets the integer value in its own way. NULL means to choose a seed based on the time, a counter, and other information likely to produce a unique values. |
kind |
can be either a string or NULL (the default). If it is a string,
it specifies the name of the desired random uniform generator. It must
be one of
"Wichmann-Hill", "Marsaglia-Multicarry", "Super-Duper", "Mersenne-Twister",
"Knuth-TAOCP", "user-supplied", "Knuth-TAOCP-2002", "L'Ecuyer-CMRG" and "default",
or an unambiguous abbreviation of one of those. Currently "default"
is equivalent to "Mersenne-Twister".
Currently, only the "Mersenne-Twister" and "L'Ecuyer-CMRG" generators are supported and all attempts to set another one result in a warning. |
normal.kind |
can be either a string or NULL (the default). If it is a string,
it specifies the name of the desired random normal generator. It must
be one of "Buggy Kinderman-Ramage", "Ahrens-Dieter", "Box-Muller",
"user-supplied", "Inversion", "Kinderman-Ramage" and "default",
or an unambiguous abbreviation of one of those. Currently "default"
is equivalent to "Inversion".
Currently, only the "Inversion" normal generator is supported and all attempts to set another one result in a warning. |
vstr |
a character string representing the R version number to be compatible with.
Only the major and minor version numbers are used in RNGversion.
Currently only version number 1.7 or later is supported. |
The dataset .Random.seed is used to store the current state of a random number generator. If it does not exist, it is created the first time a random number is generated. The RNG kind is set to "default" or to the last value used in the current session, and the seed is set to a time-based value. Essentially, .Random.seed is an integer vector with a variable length. The first element of .Random.seed records the kind and normal.kind information.
Both kind and normal.kind strings can be mapped to zero-based indices: 0, 1, 2, ..., and then the first element of .Random.seed is set to the value 100*normal.kind_index + kind_index.
The remaining elements of .Random.seed are the state of the chosen generator itself. Each generator uses .Random.seed in different ways and has its own requirements for the values in it, so it should not be modified. A user can store it and restore it to recreate a given stream of random numbers.
RNGkind | returns the previous kind and normal kind invisibly if at least one of kind or normal.kind is supplied with a new value. Returns the current kind and normal kind visibly if neither kind nor normal.kind is supplied. |
set.seed | returns NULL invisibly. |
RNGversion | returns the previous kind and normal kind invisibly. |
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Any feedback is very welcome. http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html email: m-mat \@ math.sci.hiroshima-u.ac.jp (remove space)
# Make sure the new session is started! RNGkind() # Returns "Mersenne-Twister" "Inversion" #.Random.seed # Not created yet, so an error is generated# kind and normal.kind are set and .Random.seed is created. RNGkind("L'Ecuyer-CMRG", "default") .Random.seed # 407 ... ... ....
# kind = "Mersenne-Twister" normal.kind = "Inversion" RNGversion("2.13.0")
# to reproduce random samples, start with a specified random seed: set.seed(1, "Mersenne", "Inversion") runif(5) # do some work set.seed(1, "Mersenne", "Inversion") # set the same seed again old.seed <- .Random.seed # store the seed runif(5) # repeat work: the same "random" numbers occur.
.Random.seed <<- old.seed # Reset .Random.seed in global environment runif(5) # repeat work: the same "random" numbers occur.