.Random.seed adalah vektor bilangan bulat, berisi status penghasil angka acak (RNG) untuk pembuatan angka acak di R. Dapat disimpan dan dipulihkan, namun tidak boleh diubah oleh pengguna. RNGkind adalah antarmuka yang lebih ramah untuk menanyakan atau mengatur jenis RNG yang digunakan. Versi RNG dapat digunakan untuk mengatur generator acak seperti pada versi R sebelumnya (untuk reproduktifitas). set.seed adalah cara yang disarankan untuk menentukan benih.
<code>.Random.seed <- c(rng.kind, n1, n2, \dots)</code><p></p><p>RNGkind(kind = NULL, normal.kind = NULL, sample.kind = NULL)
RNGversion(vstr)
set.seed(seed, kind = NULL, normal.kind = NULL, sample.kind = NULL)</p>
| Parameter | Deskripsi |
|---|---|
kind |
character or NULL. If kind is a character string, set R's RNG to the kind desired. Use "default" to return to the R default. See ‘Details’ for the interpretation of NULL. |
normal.kind |
character string or NULL. If it is a character string, set the method of Normal generation. Use "default" to return to the R default. NULL makes no change. |
sample.kind |
character string or NULL. If it is a character string, set the method of discrete uniform generation (used in sample, for instance). Use "default" to return to the R default. NULL makes no change. |
seed |
a single value, interpreted as an integer, or NULL (see ‘Details’). |
vstr |
a character string containing a version number, e.g., "1.6.2". The default RNG configuration of the current R version is used if vstr is greater than the current version. |
rng.kind |
integer code in 0:k for the above kind. |
n1, n2, … |
integers. See the details for how many are required (which depends on rng.kind). |
# NOT RUN {
require(stats)
## Seed the current RNG, i.e., set the RNG status
set.seed(42); u1 <- runif(30)
set.seed(42); u2 <- runif(30) # the same because of identical RNG status:
stopifnot(identical(u1, u2))
# }
# NOT RUN {
## the default random seed is 626 integers, so only print a few
runif(1); .Random.seed[1:6]; runif(1); .Random.seed[1:6]
## If there is no seed, a "random" new one is created:
rm(.Random.seed); runif(1); .Random.seed[1:6]
# }
# NOT RUN {
ok <- RNGkind()
RNGkind("Wich") # (partial string matching on 'kind')
## This shows how 'runif(.)' works for Wichmann-Hill,
## using only R functions:
p.WH <- c(30269, 30307, 30323)
a.WH <- c( 171, 172, 170)
next.WHseed <- function(i.seed = .Random.seed[-1])
{ (a.WH * i.seed) %% p.WH }
my.runif1 <- function(i.seed = .Random.seed)
{ ns <- next.WHseed(i.seed[-1]); sum(ns / p.WH) %% 1 }
set.seed(1998-12-04)# (when the next lines were added to the souRce)
rs <- .Random.seed
(WHs <- next.WHseed(rs[-1]))
u <- runif(1)
stopifnot(
next.WHseed(rs[-1]) == .Random.seed[-1],
all.equal(u, my.runif1(rs))
)
## ----
.Random.seed
RNGkind("Super") # matches "Super-Duper"
RNGkind()
.Random.seed # new, corresponding to Super-Duper
## Reset:
RNGkind(ok[1])
RNGversion(getRversion()) # the default version for this R version
## ----
sum(duplicated(runif(1e6))) # around 110 for default generator
## and we would expect about almost sure duplicates beyond about
qbirthday(1 - 1e-6, classes = 2e9) # 235,000
# }