| Line 1... |
Line 1... |
| 1 |
% File src/library/base/man/Random.Rd
|
1 |
% File src/library/base/man/Random.Rd
|
| 2 |
% Part of the R package, https://www.R-project.org
|
2 |
% Part of the R package, https://www.R-project.org
|
| 3 |
% Copyright 1995-2025 R Core Team
|
3 |
% Copyright 1995-2026 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{Random}
|
6 |
\name{Random}
|
| 7 |
\alias{Random}
|
7 |
\alias{Random}
|
| 8 |
\alias{RNG}
|
8 |
\alias{RNG}
|
| Line 25... |
Line 25... |
| 25 |
\code{set.seed} is the recommended way to specify seeds.
|
25 |
\code{set.seed} is the recommended way to specify seeds.
|
| 26 |
}
|
26 |
}
|
| 27 |
\usage{
|
27 |
\usage{
|
| 28 |
\special{.Random.seed <- c(rng.kind, n1, n2, \dots)}
|
28 |
\special{.Random.seed <- c(rng.kind, n1, n2, \dots)}
|
| 29 |
|
29 |
|
| 30 |
RNGkind(kind = NULL, normal.kind = NULL, sample.kind = NULL)
|
30 |
RNGkind(kind = NULL, normal.kind = NULL, sample.kind = NULL, binom.kind = NULL)
|
| 31 |
RNGversion(vstr)
|
31 |
RNGversion(vstr)
|
| 32 |
set.seed(seed, kind = NULL, normal.kind = NULL, sample.kind = NULL)
|
32 |
set.seed(seed, kind = NULL, normal.kind = NULL, sample.kind = NULL, binom.kind = NULL)
|
| 33 |
}
|
33 |
}
|
| 34 |
\arguments{
|
34 |
\arguments{
|
| 35 |
\item{kind}{character or \code{NULL}. If \code{kind} is a character
|
35 |
\item{kind}{character or \code{NULL}. If \code{kind} is a character
|
| 36 |
string, set \R's RNG to the kind desired. Use \code{"default"} to
|
36 |
string, set \R's RNG to the kind desired. Use \code{"default"} to
|
| 37 |
return to the \R default. See \sQuote{Details} for the
|
37 |
return to the \R default. See \sQuote{Details} for the
|
| Line 41... |
Line 41... |
| 41 |
to return to the \R default. \code{NULL} makes no change.}
|
41 |
to return to the \R default. \code{NULL} makes no change.}
|
| 42 |
\item{sample.kind}{character string or \code{NULL}. If it is a character
|
42 |
\item{sample.kind}{character string or \code{NULL}. If it is a character
|
| 43 |
string, set the method of discrete uniform generation (used in
|
43 |
string, set the method of discrete uniform generation (used in
|
| 44 |
\code{\link{sample}}, for instance). Use \code{"default"} to return to
|
44 |
\code{\link{sample}}, for instance). Use \code{"default"} to return to
|
| 45 |
the \R default. \code{NULL} makes no change.}
|
45 |
the \R default. \code{NULL} makes no change.}
|
| - |
|
46 |
\item{binom.kind}{character string or \code{NULL}. If it is a character
|
| - |
|
47 |
string, set the method of \code{\link{rbinom}()}. Use \code{"default"} to return to
|
| - |
|
48 |
the \R default. \code{NULL} makes no change.}
|
| 46 |
\item{seed}{a single value, interpreted as an integer, or \code{NULL}
|
49 |
\item{seed}{a single value, interpreted as an integer, or \code{NULL}
|
| 47 |
(see \sQuote{Details}).}
|
50 |
(see \sQuote{Details}).}
|
| 48 |
\item{vstr}{a character string containing a version number,
|
51 |
\item{vstr}{a character string containing a version number,
|
| 49 |
e.g., \code{"1.6.2"}. The default RNG configuration of the current
|
52 |
e.g., \code{"1.6.2"}. The default RNG configuration of the current
|
| 50 |
\R version is used if \code{vstr} is greater than the current version.}
|
53 |
\R version is used if \code{vstr} is greater than the current version.}
|
| Line 95... |
Line 98... |
| 95 |
|
98 |
|
| 96 |
The two seeds are the \I{Tausworthe} and congruence long integers,
|
99 |
The two seeds are the \I{Tausworthe} and congruence long integers,
|
| 97 |
respectively.
|
100 |
respectively.
|
| 98 |
|
101 |
|
| 99 |
It exhibits 25 clear failures in the \I{TestU01} Crush suite
|
102 |
It exhibits 25 clear failures in the \I{TestU01} Crush suite
|
| 100 |
\bibcitep{R:L_Ecuyer+Simard:2007}.
|
103 |
\bibcitep{R:L_Ecuyer+Simard:2007}.
|
| 101 |
}
|
104 |
}
|
| 102 |
|
105 |
|
| 103 |
\item{\code{"Mersenne-Twister"}:}{
|
106 |
\item{\code{"Mersenne-Twister"}:}{
|
| 104 |
From \bibcitet{R:Matsumoto+Nishimura:1998}; code updated in 2002.
|
107 |
From \bibcitet{R:Matsumoto+Nishimura:1998}; code updated in 2002.
|
| 105 |
A twisted \abbr{GFSR} with period
|
108 |
A twisted \abbr{GFSR} with period
|
| Line 184... |
Line 187... |
| 184 |
|
187 |
|
| 185 |
\code{sample.kind} can be \code{"Rounding"} or \code{"Rejection"},
|
188 |
\code{sample.kind} can be \code{"Rounding"} or \code{"Rejection"},
|
| 186 |
or partial matches to these. The former was the default in versions
|
189 |
or partial matches to these. The former was the default in versions
|
| 187 |
prior to 3.6.0: it made \code{\link{sample}} noticeably non-uniform
|
190 |
prior to 3.6.0: it made \code{\link{sample}} noticeably non-uniform
|
| 188 |
on large populations, and should only be used for reproduction of old
|
191 |
on large populations, and should only be used for reproduction of old
|
| 189 |
results. See \PR{17494} for a discussion.
|
192 |
results. See \PR{17494} for a discussion.
|
| - |
|
193 |
|
| - |
|
194 |
\code{binom.kind} can be \code{"Buggy BTPE"} or \code{"BTPE"},
|
| - |
|
195 |
or partial matches to these. The former was the default in versions
|
| - |
|
196 |
prior to 4.7.0: for large but not very large mean,
|
| - |
|
197 |
\code{\link{rbinom}()}'s acceptance-rejection algorithm accepted
|
| - |
|
198 |
very few \dQuote{outer tail} values it should have rejected, leading to a
|
| - |
|
199 |
very slightly increased distribution tail weight. See \PR{19049} for more.
|
| - |
|
200 |
|
| 190 |
|
201 |
|
| 191 |
\code{set.seed} uses a single integer argument to set as many seeds
|
202 |
\code{set.seed()} uses a single integer argument to set as many seeds
|
| 192 |
as are required. It is intended as a simple way to get quite different
|
203 |
as are required. It is intended as a simple way to get quite different
|
| 193 |
seeds by specifying small integer arguments, and also as a way to get
|
204 |
seeds by specifying small integer arguments, and also as a way to get
|
| 194 |
valid seed sets for the more complicated methods (especially
|
205 |
valid seed sets for the more complicated methods (especially
|
| 195 |
\code{"Mersenne-Twister"} and \code{"Knuth-TAOCP"}). There is no
|
206 |
\code{"Mersenne-Twister"} and \code{"Knuth-TAOCP"}). There is no
|
| 196 |
guarantee that different values of \code{seed} will seed the RNG
|
207 |
guarantee that different values of \code{seed} will seed the RNG
|
| 197 |
differently, although any exceptions would be extremely rare. If
|
208 |
differently, although any exceptions would be extremely rare. If
|
| 198 |
called with \code{seed = NULL} it re-initializes (see \sQuote{Note})
|
209 |
called with \code{seed = NULL} it re-initializes (see \sQuote{Note})
|
| 199 |
as if no seed had yet been set.
|
210 |
as if no seed had yet been set.
|
| 200 |
|
211 |
|
| 201 |
The use of \code{kind = NULL}, \code{normal.kind = NULL} or
|
212 |
The use of \code{kind = NULL}, \code{normal.kind = NULL},
|
| 202 |
\code{sample.kind = NULL} in
|
213 |
\code{sample.kind = NULL} or \code{binom.kind = NULL} in
|
| 203 |
\code{RNGkind} or \code{set.seed} selects the currently-used
|
214 |
\code{RNGkind} or \code{set.seed} selects the currently-used
|
| 204 |
generator (including that used in the previous session if the
|
215 |
generator (including that used in the previous session if the
|
| 205 |
workspace has been restored): if no generator has been used it selects
|
216 |
workspace has been restored): if no generator has been used it selects
|
| 206 |
\code{"default"}.
|
217 |
\code{"default"}.
|
| 207 |
}
|
218 |
}
|
| Line 240... |
Line 251... |
| 240 |
In the underlying C, \code{.Random.seed[-1]} is \code{unsigned};
|
251 |
In the underlying C, \code{.Random.seed[-1]} is \code{unsigned};
|
| 241 |
therefore in \R \code{.Random.seed[-1]} can be negative or perhaps
|
252 |
therefore in \R \code{.Random.seed[-1]} can be negative or perhaps
|
| 242 |
\code{\link{NA_integer_}}, due to
|
253 |
\code{\link{NA_integer_}}, due to
|
| 243 |
the representation of an unsigned integer by a signed integer.
|
254 |
the representation of an unsigned integer by a signed integer.
|
| 244 |
|
255 |
|
| 245 |
\code{RNGkind} returns a three-element character vector of the RNG,
|
256 |
\code{RNGkind} returns the character vector of the RNG and other kinds
|
| 246 |
normal and sample kinds selected \emph{before} the call, invisibly if
|
257 |
selected \emph{before} the call, invisibly if
|
| 247 |
either argument is not \code{NULL}. A type starts a session as the
|
258 |
either argument is not \code{NULL}. A type starts a session as the
|
| 248 |
default, and is selected either by a call to \code{RNGkind} or by setting
|
259 |
default, and is selected either by a call to \code{RNGkind} or by setting
|
| 249 |
\code{.Random.seed} in the workspace. (NB: prior to \R 3.6.0 the first
|
260 |
\code{.Random.seed} in the workspace. (NB: prior to \R 3.6.0 the first
|
| 250 |
two kinds were returned in a two-element character vector.)
|
261 |
two kinds were returned in a two-element character vector.)
|
| 251 |
|
262 |
|