RandIntegers

Selects random integers between and inclusive of specified lower and upper limits.
1.5K Downloads
Updated 17 Jan 2006

View License

RANDINTEGERS(LOWER_BOUND,UPPER_BOUND) is a one line function that uses RAND to return a random integer between and inclusive of the two specified integers LOWER_BOUND and UPPER_BOUND (with uniform probability) (and with replacement).

The third argument M_SIZE is optional. If specified as a scalar, the output is a matrix with size [m_size m_size] and containing the values stated above. If specified as a row vector, the output is an array with size [m_size] and containing the same.

Examples:

randinteger(11,25) may return 23 or 25 or 11
randinteger(11,25,2) may return [25 12; 15 24]
randinteger(11,25,[1 3]) may return [14 23 17]

Remarks:

As depicted in the help text within the function, the Communications and Statistics toolboxes each contain a function that can be used for the same purpose.

[Please subscribe to this file if you use it, so you can be notified of updates.]

Cite As

Skynet (2024). RandIntegers (https://www.mathworks.com/matlabcentral/fileexchange/6207-randintegers), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP3
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Creating and Concatenating Matrices in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0

Fixed minor error in Summary.