rndBinomial#
Purpose#
Computes binomial pseudo-random numbers with the choice of underlying random number generator.
Format#
- x = rndBinomial(r, c, trials, prob)#
- { x, newstate } = rndBinomial(r, c, trials, prob, state)
- Parameters:
r (scalar) – number of rows of resulting matrix.
c (scalar) – number of columns of resulting matrix.
trials (matrix or vector or scalar) – the number of trials, scalar or ExE conformable with r and c.
prob (matrix or vector or scalar) – the probability of success of each trial, scalar or ExE conformable with r and c.
state (scalar or opaque vector) –
Optional argument.
scalar case
state = starting seed value only. If -1, GAUSS computes the starting seed based on the system clock.
opaque vector case
state = the state vector returned from a previous call to one of the
rnd
random number functions.
- Returns:
x (RxC matrix) – binomially distributed random numbers.
newstate (Opaque vector) – the updated state.
Examples#
Basic usage#
// Set seed for repeatable random numbers
rndseed 7345;
// Simulate the number of successes from 1024 trials,
// each of which have a 40% chance of success, 3 times
n = 1024;
p = 0.4;
k = rndBinomial(3, 1, n, p);
After the code above, k should equal:
413
390
427
Pass seed and return state vector#
// Simulate the number of successes from 1024 trials,
// each of which have a 40% chance of success, 3 times
n = 1024;
p = 0.4;
// Pass in seed as optional final input argument
// and return state vector as second output
{ k, state } = rndBinomial(3, 1, n, p, 7345);
After the code above, k should equal:
413
390
427
Technical Notes#
The default generator for func:rndBinomial
is the SFMT Mersenne-Twister
19937. You can specify a different underlying random number generator
with the function rndCreateState()
.
Remarks#
The properties of the pseudo-random numbers in x are:
r and c will be truncated to integers if necessary.
See also
Functions rndCreateState()
, rndStateSkip()