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.
Seed = s>)
stats::hypergeometricRandom(N, X, n) returns
a procedure that produces hypergeometric-deviates
(random numbers) with population size
X and sample size
n) can be called in the form
The return value of
f(x) is either an integer
between max(0, X + n - N) and min(X, n) or
a symbolic expression:
N is a positive integer and both
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
n)() is returned in all other cases.
Numerical values for
N are only accepted
if they are positive integers.
Numerical values for
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
For any max(0, X + n - N) ≤ x ≤ min(X, n), the probability of R ≤ x is given by
Without the option
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 re-initialized with the
reset function, random generators produce
the same sequences of numbers.
With this option, the parameters
evaluate to suitable numerical values at the time, when the generator
For efficiency, it is recommended to produce sequences of K random numbers via
f := stats::hypergeometricRandom(N, X, n): f() $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
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
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
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
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 pseudo-random numbers. The generator is initialized with
When this option is used, the parameters