Namespace: go.std.math.rand
v1.0Contents
Summary
Provides a low-level interface to the math/rand package.
Package rand implements pseudo-random number generators unsuitable for
security-sensitive work.
Random numbers are generated by a Source. Top-level functions, such as
Float64 and Int, use a default shared Source that produces a deterministic
sequence of values each time a program is run. Use the Seed function to
initialize the default Source if different behavior is required for each run.
The default Source is safe for concurrent use by multiple goroutines, but
Sources created by NewSource are not.
This package's outputs might be easily predictable regardless of how it's
seeded. For random numbers suitable for security-sensitive work, see the
crypto/rand package.
Index
- *Rand
- *Zipf
- ExpFloat64
- Float32
- Float64
- Int
- Int31
- Int31n
- Int63
- Int63n
- Intn
- New
- NewSource
- NewZipf
- NormFloat64
- Perm
- Rand
- Read
- Seed
- Source
- Source64
- Uint32
- Uint64
- Zipf
- arrayOfRand
- arrayOfSource
- arrayOfSource64
- arrayOfZipf
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
(None.)
Functions, Macros, and Special Forms
-
ExpFloat64
Function v1.0(ExpFloat64)
ExpFloat64 returns an exponentially distributed float64 in the range
(0, +math.MaxFloat64] with an exponential distribution whose rate parameter
(lambda) is 1 and whose mean is 1/lambda (1) from the default Source.
To produce a distribution with a different rate parameter,
callers can adjust the output using:
sample = ExpFloat64() / desiredRateParameter
Go returns: float64
Joker input arguments: []
Joker returns: ^Double -
Float32
Function v1.0(Float32)
Float32 returns, as a float32, a pseudo-random number in the half-open interval [0.0,1.0)
from the default Source.
Go returns: float32
Joker input arguments: []
Joker returns: ^Double -
Float64
Function v1.0(Float64)
Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0)
from the default Source.
Go returns: float64
Joker input arguments: []
Joker returns: ^Double -
Int
Function v1.0(Int)
Int returns a non-negative pseudo-random int from the default Source.
Go returns: int
Joker input arguments: []
Joker returns: ^Int -
Int31
Function v1.0(Int31)
Int31 returns a non-negative pseudo-random 31-bit integer as an int32
from the default Source.
Go returns: int32
Joker input arguments: []
Joker returns: ^Int -
Int31n
Function v1.0(Int31n n)
Int31n returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n)
from the default Source.
It panics if n <= 0.
Go input arguments: (n int32)
Go returns: int32
Joker input arguments: [^Int n]
Joker returns: ^Int -
Int63
Function v1.0(Int63)
Int63 returns a non-negative pseudo-random 63-bit integer as an int64
from the default Source.
Go returns: int64
Joker input arguments: []
Joker returns: ^BigInt -
Int63n
Function v1.0(Int63n n)
Int63n returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n)
from the default Source.
It panics if n <= 0.
Go input arguments: (n int64)
Go returns: int64
Joker input arguments: [^BigInt n]
Joker returns: ^BigInt -
Intn
Function v1.0(Intn n)
Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n)
from the default Source.
It panics if n <= 0.
Go input arguments: (n int)
Go returns: int
Joker input arguments: [^Int n]
Joker returns: ^Int -
New
Function v1.0(New src)
New returns a new Rand that uses random values from src
to generate other random values.
Go input arguments: (src Source)
Go returns: *Rand
Joker input arguments: [^Source src]
Joker returns: ^*Rand -
NewSource
Function v1.0(NewSource seed)
NewSource returns a new pseudo-random Source seeded with the given value.
Unlike the default Source used by top-level functions, this source is not
safe for concurrent use by multiple goroutines.
Go input arguments: (seed int64)
Go returns: Source
Joker input arguments: [^BigInt seed]
Joker returns: ^Source -
NewZipf
Function v1.0(NewZipf r s v imax)
NewZipf returns a Zipf variate generator.
The generator generates values k ∈ [0, imax]
such that P(k) is proportional to (v + k) ** (-s).
Requirements: s > 1 and v >= 1.
Go input arguments: (r *Rand, s float64, v float64, imax uint64)
Go returns: *Zipf
Joker input arguments: [^*Rand r, ^Double s, ^Double v, ^Number imax]
Joker returns: ^*Zipf -
NormFloat64
Function v1.0(NormFloat64)
NormFloat64 returns a normally distributed float64 in the range
[-math.MaxFloat64, +math.MaxFloat64] with
standard normal distribution (mean = 0, stddev = 1)
from the default Source.
To produce a different normal distribution, callers can
adjust the output using:
sample = NormFloat64() * desiredStdDev + desiredMean
Go returns: float64
Joker input arguments: []
Joker returns: ^Double -
Perm
Function v1.0(Perm n)
Perm returns, as a slice of n ints, a pseudo-random permutation of the integers
in the half-open interval [0,n) from the default Source.
Go input arguments: (n int)
Go returns: []int
Joker input arguments: [^Int n]
Joker returns: ^arrayOfInt -
Read
Function v1.0(Read p)
Read generates len(p) random bytes from the default Source and
writes them into p. It always returns len(p) and a nil error.
Read, unlike the Rand.Read method, is safe for concurrent use.
Go input arguments: (p []byte)
Go returns: (n int, err error)
Joker input arguments: [^arrayOfByte p]
Joker returns: [^Int n, ^Error err] -
Seed
Function v1.0(Seed seed)
Seed uses the provided seed value to initialize the default Source to a
deterministic state. If Seed is not called, the generator behaves as
if seeded by Seed(1). Seed values that have the same remainder when
divided by 2³¹-1 generate the same pseudo-random sequence.
Seed, unlike the Rand.Seed method, is safe for concurrent use.
Go input arguments: (seed int64)
Joker input arguments: [^BigInt seed] -
Uint32
Function v1.0(Uint32)
Uint32 returns a pseudo-random 32-bit value as a uint32
from the default Source.
Go returns: uint32
Joker input arguments: []
Joker returns: ^Number -
Uint64
Function v1.0(Uint64)
Uint64 returns a pseudo-random 64-bit value as a uint64
from the default Source.
Go returns: uint64
Joker input arguments: []
Joker returns: ^Number
Types
-
*Rand
Concrete Type v1.0A Rand is a source of random numbers.
-
ExpFloat64
Receiver for *Rand v1.0([])
ExpFloat64 returns an exponentially distributed float64 in the range
(0, +math.MaxFloat64] with an exponential distribution whose rate parameter
(lambda) is 1 and whose mean is 1/lambda (1).
To produce a distribution with a different rate parameter,
callers can adjust the output using:
sample = ExpFloat64() / desiredRateParameter
-
Float32
Receiver for *Rand v1.0([])
Float32 returns, as a float32, a pseudo-random number in the half-open interval [0.0,1.0).
-
Float64
Receiver for *Rand v1.0([])
Float64 returns, as a float64, a pseudo-random number in the half-open interval [0.0,1.0).
-
Int
Receiver for *Rand v1.0([])
Int returns a non-negative pseudo-random int.
-
Int31
Receiver for *Rand v1.0([])
Int31 returns a non-negative pseudo-random 31-bit integer as an int32.
-
Int31n
Receiver for *Rand v1.0([n])
Int31n returns, as an int32, a non-negative pseudo-random number in the half-open interval [0,n).
It panics if n <= 0.
-
Int63
Receiver for *Rand v1.0([])
Int63 returns a non-negative pseudo-random 63-bit integer as an int64.
-
Int63n
Receiver for *Rand v1.0([n])
Int63n returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n).
It panics if n <= 0.
-
Intn
Receiver for *Rand v1.0([n])
Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n).
It panics if n <= 0.
-
NormFloat64
Receiver for *Rand v1.0([])
NormFloat64 returns a normally distributed float64 in
the range -math.MaxFloat64 through +math.MaxFloat64 inclusive,
with standard normal distribution (mean = 0, stddev = 1).
To produce a different normal distribution, callers can
adjust the output using:
sample = NormFloat64() * desiredStdDev + desiredMean
-
Perm
Receiver for *Rand v1.0([n])
Perm returns, as a slice of n ints, a pseudo-random permutation of the integers
in the half-open interval [0,n).
-
Read
Receiver for *Rand v1.0([p])
Read generates len(p) random bytes and writes them into p. It
always returns len(p) and a nil error.
Read should not be called concurrently with any other Rand method.
-
Seed
Receiver for *Rand v1.0([seed])
Seed uses the provided seed value to initialize the generator to a deterministic state.
Seed should not be called concurrently with any other Rand method.
-
Uint32
Receiver for *Rand v1.0([])
Uint32 returns a pseudo-random 32-bit value as a uint32.
-
Uint64
Receiver for *Rand v1.0([])
Uint64 returns a pseudo-random 64-bit value as a uint64.
-
*Zipf
Concrete Type v1.0A Zipf generates Zipf distributed variates.
-
Uint64
Receiver for *Zipf v1.0([])
Uint64 returns a value drawn from the Zipf distribution described
by the Zipf object.
-
Rand
Concrete Type v1.0A Rand is a source of random numbers.
-
Source
Abstract Type v1.0A Source represents a source of uniformly-distributed
pseudo-random int64 values in the range [0, 1<<63).
-
Int63
Method for Source v1.0([])
-
Seed
Method for Source v1.0([seed])
-
Source64
Abstract Type v1.0A Source64 is a Source that can also generate
uniformly-distributed pseudo-random uint64 values in
the range [0, 1<<64) directly.
If a Rand r's underlying Source s implements Source64,
then r.Uint64 returns the result of one call to s.Uint64
instead of making two calls to s.Int63.
-
Int63
Method for Source64 v1.0([])
-
Seed
Method for Source64 v1.0([seed])
-
Uint64
Method for Source64 v1.0([])
-
Zipf
Concrete Type v1.0A Zipf generates Zipf distributed variates.
-
arrayOfRand
Concrete Type v1.0A Rand is a source of random numbers.
-
arrayOfSource
Concrete Type v1.0A Source represents a source of uniformly-distributed
pseudo-random int64 values in the range [0, 1<<63).
-
arrayOfSource64
Concrete Type v1.0A Source64 is a Source that can also generate
uniformly-distributed pseudo-random uint64 values in
the range [0, 1<<64) directly.
If a Rand r's underlying Source s implements Source64,
then r.Uint64 returns the result of one call to s.Uint64
instead of making two calls to s.Int63.
-
arrayOfZipf
Concrete Type v1.0A Zipf generates Zipf distributed variates.