Generate a random number generator for hypergeometric deviates
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
stats::hypergeometricRandom(N
, X
, n
, <Seed = s
>)
stats::hypergeometricRandom(N, X, n)
returns
a procedure that produces hypergeometricdeviates
(random numbers) with population size N
, success
population size X
and sample size n
.
The procedure f:=stats::hypergeometricRandom(N, X,
n)
can be called in the form f()
.
The return value of f(x)
is either an integer
between max(0, X + n  N) and min(X, n) or
a symbolic expression:
If N
is a positive integer and both X
and n
are
nonnegative integers, then an explicit numerical value is returned.
If any of the parameters is symbolic, then in some cases numerical or symbolic result will be returned:
0 will be returned if either n or X is zero, n will be returned if N = X and X will be returned if N = n.
The symbolic call stats::hypergeometricRandom(N, X,
n)()
is returned in all other cases.
Numerical values for N
are only accepted
if they are positive integers.
Numerical values for X
and n
are
only accepted if they are integers that satisfy 0
≤ X, n ≤ N.
The values R = f() are
distributed randomly according to the hypergeometric distribution
with poupulation size N
, success population size X
and
sample size n
.
For any max(0, X + n  N) ≤ x ≤ min(X, n), the probability of R ≤ x is given by
.
Without the option Seed
= s
,
an initial seed is chosen internally. This initial seed is set to
a default value when MuPAD^{®} is started. Thus, each time MuPAD is
started or reinitialized with the reset
function, random generators produce
the same sequences of numbers.
Note:
With this option, the parameters 
Note:
In contrast to the function 
For efficiency, it is recommended to produce sequences of K random numbers via
f := stats::hypergeometricRandom(N, X, n): f() $k
= 1..K;
rather than by
stats::hypergeometricRandom(N, X, n)() $k = 1..K;
The latter call produces a sequence of generators each of which is called once. Also note that
stats::hypergeometricRandom(N, X, n, Seed = s)() $k
= 1..K;
does not produce a random sequence, because a sequence of freshly initialized generators would be created each of them producing the same number.
The function is sensitive to the environment variable DIGITS
which
determines the numerical working precision.
We generate hypergeometric deviates with parameters N = 100, X = 30, and n = 7:
f := stats::hypergeometricRandom(100, 30, 7): f() $ k = 1..10
delete f:
With symbolic parameters, no random numbers can be produced:
f := stats::hypergeometricRandom(N, X, n): f()
When N, X and n evaluate to suitable numbers, the generator starts to produce random numbers:
N := 200: X := 80: n := 20: f() $ k= 1..10
delete f, N, X, n:
We use the option Seed
= s
to
reproduce a sequence of random numbers:
f := stats::hypergeometricRandom(500, 100, 50, Seed = 1): f() $ k = 1..10
g := stats::hypergeometricRandom(500, 100, 50, Seed = 1): g() $ k = 1..10
f() = g(), f() = g()
delete f, g:

The "population size": an arithmetical expression representing a positive integer 

The "success population size": an arithmetical expression representing a nonnegative integer 

The "sample size": an arithmetical expression representing a nonnegative integer 

Option, specified as Initializes the random generator with the integer seed This option serves for generating generators that return predictable
sequences of pseudorandom numbers. The generator is initialized with
the seed When this option is used, the parameters 