No BSD License  

4.8

4.8 | 11 ratings Rate this file 6 Downloads (last 30 days) File Size: 1.96 KB File ID: #5346

MYRANDINT -- Random Integer Generation

by

 

24 Jun 2004 (Updated )

Random integers drawn uniformly from a specified set.

| Watch this File

File Information
Description

Returns a matrix of random elements drawn uniformly from within a specified set. Sampling can be done with or without replacement. (This function was intended to fill the role of RANDINT in the Comm Toolbox, which I no longer possess. No claims are made for correctness or efficiency.)

Acknowledgements

This file inspired Random Integer Generator and Generate Uniform Pseudo Random Integers From Linear Range..

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (12)
10 Jun 2010 Dane Fratanduono

Program works correctly, I just forgot to bin the histogram. Sorry for any confusion.

10 Jun 2010 Dane Fratanduono

Program does not work well when randomly generating numbers when drawn without replacement. This can be observed by using the program to randomly obtain values within a range. Sort the results and plot using a histogram. It appears that the limits in and the middle value of the range are preferentially treated.

clc;
clear;
close all;
for n = 1:10000
p(n,:) = myrandint(1,3,[1:23],'noreplace');
end

a = sort(p);
hist(a)

21 Apr 2010 ILKER OZCELIK

Thank you for the code. ..

18 Mar 2008 n w

why don't you just use something like
ceil(rand(n,m)*t) ??
This will generate an nxm matrix with randomly chosen integers from 1 to t.

13 Feb 2008 Phillip Feldman

This is a simple but nicely crafted replacement for the randint() function. The only drawback that I can see if that rand(), which generates random double-precision floats, it being used to generate random integers. It should be possible to generate random integers without doing floating point operations.

28 Nov 2007 asim nadeem

It is an excellent function can used to generate random problems for linear programming.

20 Aug 2007 Yogesh Parte

Very good and handly function.

26 Mar 2007 Jeremy Watt

Very cool, thanks much.

10 Jun 2006 Makio Tamura  
19 May 2006 Dimitris DenXreiazetai

very good, works fine, if you don't know that it is missing from the standard libraries you may seach for hours in the Help files

18 Jul 2005 Elan Barenholtz

Thanks for some very useful code. This guy is a master!

08 Mar 2005 Muhammad Ilyas Mazhar  
Updates
01 Jul 2004

I removed the silly FOR loop.

Contact us