Generate uniform pseudo-random integers from linear range.

Versione 1.4.0.0 (1,47 KB) da DS
RAND_INT(R,N) returns an n-by-n matrix containing pseudo-random integer values from range R.
468 download
Aggiornato 27 gen 2014

Visualizza la licenza

Function that uses RAND to generate random integers in the specified linear range, as follows:

result = floor(a + (b-a+1).* rand(N)),
where specified range is [a b]

-----
Please note: There are lots of ways to do this and lots of interesting submissions on FEX which provide similar results (see below).

random numbers:

#18443 - Random Integer Generator
#5346 - MYRANDINT -- Random Integer Generation
#27942 - WWW.RANDOM.ORG random integers/sequences/strings
#27809 - Unique Random Integer List
#13007 - Random Number Generator
#21353 - True Random Integer Generator (random.org)

random arrangement:

#30189 - RANDPERMFULL (derangement)
#17981 - RANDBLOCK
#27076 - Shuffle

Cita come

DS (2024). Generate uniform pseudo-random integers from linear range. (https://www.mathworks.com/matlabcentral/fileexchange/35324-generate-uniform-pseudo-random-integers-from-linear-range), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2007b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Categorie
Scopri di più su Random Number Generation in Help Center e MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Versione Pubblicato Note della release
1.4.0.0

Modified code included as detailed in previous update.

1.3.0.0

Added a check for imaginary and non-integer range specifications. Thanks to Travis B for pointing out this edge-case behavior.

1.2.0.0

Fixed help format to accommodate LOOKFOR queries.

1.1.0.0

Thanks to Jan Simon for suggesting the use of numel instead of abusing the size function (see comments).

1.0.0.0