rndBernoulli

Purpose

Computes Bernoulli distributed random numbers.

Format

r = rndBernoulli(r, c, prob)
{ r, newstate } = rndBernoulli(r, c, prob, state)
Parameters:
  • r (scalar) – number of rows of the output matrix.

  • c (scalar) – number of columns of the output matrix.

  • prob (scalar) – probability parameter.

  • 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:
  • r (RxC matrix) – Bernoulli random numbers.

  • newstate (Opaque vector) – the updated state.

Examples

// Bernoulli random numbers can be used to model qualitative
// binary data (i.e., yes/no, true/false), such as marital
// status.

// Set the random seed for repeatable numbers.
rndseed 723940439;

// The percentage of married people in the population we
// would like to model.
prob = 0.7;

// Create 10,000 Bernoulli random numbers
r = rndBernoulli(10000, 1, prob);

// The mean of 'r' should approximately equal 'prob'
mu = meanc(r);
print mu;
0.70270000

Remarks

The properties of the pseudo-random numbers in x are:

\[ \begin{align}\begin{aligned}E(X) = prob\\Var(X) = prob * (1 - prob)\end{aligned}\end{align} \]

See also

Functions rndMVn(), rndCreateState()