MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi
Learn moreOpportunities for recent engineering grads.
Apply TodayNew to MATLAB?
MATLAB Central > MATLAB Newsreader > Randomly permute a given set of numbers 

Subject: Randomly permute a given set of numbers From: Venkatesh Date: 12 Sep, 2010 06:00:05 Message: 1 of 12 
I have a question wherein I am required to generate integers between 2 and m randomly, without repetition (in an n x m matrix). Therefore, total number of integers generated in a row must be m, with at least two nonzero values. Any way to do this? 
Subject: Randomly permute a given set of numbers From: Ross W Date: 12 Sep, 2010 06:09:04 Message: 2 of 12 
"Venkatesh " <svthegreat@gmail.com> wrote in message <i6hq95$fjn$1@fred.mathworks.com>... 
Subject: Randomly permute a given set of numbers From: Venkatesh Date: 12 Sep, 2010 06:24:05 Message: 3 of 12 
randperm(n) generates integers from 1 to n. So it can be used to generate the integers, but what about filling the remaining positions by zeros? 
Subject: Randomly permute a given set of numbers From: Matt Fig Date: 12 Sep, 2010 06:38:03 Message: 4 of 12 
"Venkatesh " <svthegreat@gmail.com> wrote in message <i6hq95$fjn$1@fred.mathworks.com>... 
Subject: Randomly permute a given set of numbers From: Venkatesh Date: 12 Sep, 2010 07:05:06 Message: 5 of 12 
Sorry, my mistake. The _no. of integers_ generated must be in the range 2 to m. 
Subject: Randomly permute a given set of numbers From: Ross W Date: 12 Sep, 2010 07:21:06 Message: 6 of 12 
"Venkatesh " <svthegreat@gmail.com> wrote in message <i6hu32$cb$1@fred.mathworks.com>... 
Subject: Randomly permute a given set of numbers From: Bruno Luong Date: 12 Sep, 2010 08:41:07 Message: 7 of 12 
n=100; m=5; 
Subject: Randomly permute a given set of numbers From: Bruno Luong Date: 12 Sep, 2010 09:00:07 Message: 8 of 12 
To generate random array having an equiprobability for each individual combination, this code should be used: 
Subject: Randomly permute a given set of numbers From: Roger Stafford Date: 12 Sep, 2010 18:22:03 Message: 9 of 12 
Venkatesh didn't make it clear what relative frequencies are desired for the different nonzero row counts. If each count is assumed to have an equal probability, one could simply do this: 
Subject: Randomly permute a given set of numbers From: Bruno Luong Date: 12 Sep, 2010 19:07:04 Message: 10 of 12 
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i6j5ob$i4i$1@fred.mathworks.com>... 
Subject: Randomly permute a given set of numbers From: Roger Stafford Date: 12 Sep, 2010 19:39:03 Message: 11 of 12 
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i6j8co$6h7$1@fred.mathworks.com>... 
Subject: Randomly permute a given set of numbers From: Bruno Luong Date: 12 Sep, 2010 19:55:04 Message: 12 of 12 
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i6ja8n$4kk$1@fred.mathworks.com>... 
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.