randi
Uniformly distributed random integers.
Syntax
Section titled “Syntax”r = randi(imax) % scalar in [1, imax]r = randi(imax, n) % n×nr = randi(imax, m, n) % m×nr = randi([imin imax], …) % range [imin, imax]Description
Section titled “Description”Returns pseudorandom integers drawn uniformly from [1, imax], or from [imin, imax] when the first argument is a two-element vector. Both endpoints are inclusive. Result type is always int32.
Examples
Section titled “Examples”randi(10) % integer in [1,10]randi(6, 1, 100) % 100 dice rollsrandi([0 9], 3) % 3×3 of digits 0-9