Code covered by the BSD License  

Highlights from
Unique Random Integer List

Be the first to rate this file! 11 Downloads (last 30 days) File Size: 1.13 KB File ID: #27809

Unique Random Integer List

by Ibraheem Al-Dhamari

 

31 May 2010

A simple function that produce unique random Integer List

| Watch this File

File Information
Description

Usage r=myrand(a,b)
a and b is the range, for example if we want to generate random integers between 370 and 55780 we call the function :
    r=myrand(370,55780)
We can also limit the list as we need. for example if we want only 10 random integers between 370 and 55780 we use:
r10=r(1:10;
It is also useful for scrambling an array randomly.

Acknowledgements

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

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
integer, random, scramble, shuffle, unique
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
14 Sep 2011 Jimbo B

Should be
"for i=1:(b-a)+1" not

"for i=1:(b-a)" otherwise the final element in the array will never change from value of b

02 Jun 2010 Ibraheem Al-Dhamari

Hi Jan, Thanks for your comment.
I don't know about these algorithms, I jut wrote this algorithm when I neddeed it, It may be written in the past by someone, I am not sure. Please, provide the references of the algorithms you mentioned.
Regards,

02 Jun 2010 Jan Simon

It is worth to mention in the help section, that you use the Knuth- or Fisher-Yates-Shuffle algorithm. There are several other implementations in the FEX using this method.

02 Jun 2010 Ibraheem Al-Dhamari

Thanks for your comment. Yes, you are right Darren.And here is the code:
r=a:b;
tmp=randperm(b-a+1);
r=r(tmp);

But my algorithm can be implemented in other programming languages where there is no randperm.

01 Jun 2010 Darren Rowland

You can achieve the same behaviour with the function randperm too

Contact us