This is machine translation

Translated by Microsoft


Discrete uniform random numbers


R = unidrnd(N)
R = unidrnd(N,m,n,...)
R = unidrnd(N,[m,n,...])


R = unidrnd(N) generates random numbers for the discrete uniform distribution with maximum N. The parameters in N must be positive integers. N can be a vector, a matrix, or a multidimensional array. The size of R is the size of N. The discrete uniform distribution arises from experiments equivalent to drawing a number from one to N out of a hat.

R = unidrnd(N,m,n,...) or R = unidrnd(N,[m,n,...]) generates an m-by-n-by-... array. The N parameter can be a scalar or an array of the same size as R.


In the Massachusetts lottery, a player chooses a four-digit number. Generate random numbers for Monday through Saturday.

numbers = unidrnd(10000,1,6)-1
numbers =
    4564  185  8214  4447  6154  7919

Introduced before R2006a

Was this topic helpful?