rndKMnb#
Purpose#
Computes negative binomial pseudo-random numbers.
Format#
- { x, newstate } = rndKMnb(r, c, k, p, state)#
- Parameters:
r (scalar) – number of rows of resulting matrix.
c (scalar) – number of columns of resulting matrix.
k (matrix or vector or scalar) – “event” argument for negative binomial distribution, scalar or ExE conformable matrix with r and c.
p (matrix or vector or scalar) – “probability” argument for negative binomial distribution, scalar or ExE conformable matrix with r and c.
state (scalar or 500x1 vector) –
scalar case
state = starting seed value only. If -1, GAUSS computes the starting seed based on the system clock.
500x1 vector case
state = the state vector returned from a previous call to one of the
rndKMrandom number functions.
- Returns:
x (RxC matrix) – negative binomial distributed random numbers.
newstate (500x1 vector) – the updated state.
Remarks#
The properties of the pseudo-random numbers in x are:
r and c will be truncated to integers if necessary.
Examples#
// Generate a 3x2 matrix of negative binomial
// random numbers with k = 5 and p = 0.3
// using a fixed seed for repeatable output
{ x, newstate } = rndKMnb(3, 2, 5, 0.3, 12345);
print x;
The output is a 3x2 matrix of non-negative integers. The theoretical mean is k*p/(1-p) = 5*0.3/0.7, which is approximately 2.14:
3.0000000 1.0000000
1.0000000 3.0000000
1.0000000 1.0000000
Technical Notes#
rndKMnb() uses the recur-with-carry KISS+Monster algorithm described in the rndKMi() Technical Notes.
Source#
randkm.src