ID EN
System & OS

Random

R Base 3.6.2 🇮🇩 Bahasa Indonesia

.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.

Syntax

R
<code>.Random.seed &lt;- 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>

Arguments

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, &#8230; integers. See the details for how many are required (which depends on rng.kind).

Return Value

.Random.seed adalah vektor bilangan bulat yang elemen pertamanya mengkodekan jenis RNG dan generator normal. Dua digit desimal terendah ada pada 0:(k-1) dengan k adalah jumlah RNG yang tersedia. Ratusan mewakili tipe generator normal (mulai dari 0), dan sepuluh ribu mewakili tipe sampler seragam diskrit. Di C yang mendasarinya, .Random.seed[-1] tidak ditandatangani; oleh karena itu di R .Random.seed[-1] bisa negatif, karena representasi bilangan bulat tak bertanda dengan bilangan bulat bertanda. jenis RNG

Details

Jenis RNG yang tersedia saat ini diberikan di bawah ini. kind sebagian cocok dengan daftar ini. Standarnya adalah "Mersenne-Twister". "Wichmann-Hill" Benih, .Random.seed[-1] == r[1:3] adalah vektor bilangan bulat dengan panjang 3, di mana setiap r[i] berada dalam 1:(p[i] - 1), dengan p adalah vektor panjang 3 bilangan prima, p = (30269, 30307, ​​30323). Generator Wichmann--Hill memiliki panjang siklus \(6.9536 \times 10^{12}\) (= prod(p-1)/4, lihat Statistik Terapan (1984) 33, 123 yang mengoreksi artikel asli).." Marsaglia-Multicarry": RNG perkalian dengan carry digunakan, seperti yang direkomendasikan oleh George Marsaglia dalam postingannya ke milis sci.stat.math. Ia memiliki periode lebih dari \(2^{60}\) dan telah lulus semua pengujian (menurut Marsaglia). Benihnya adalah dua bilangan bulat (semua nilai diperbolehkan)."Super-Duper": Super Marsaglia yang terkenal

Contoh

Example
R
# 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
# }

See Also

sample for random sampling with and without replacement. Distributions for functions for random-variate generation from standard distributions.