Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to generate non-repeating random integers

Subject: How to generate non-repeating random integers

From: Gonzalo

Date: 26 May, 2010 21:42:04

Message: 1 of 4

Hi all,

Does anybody know how to generate a series of say 450 non-repeating random integers between 0 and 2000?

Thanks

Subject: How to generate non-repeating random integers

From: Roger Stafford

Date: 26 May, 2010 22:03:06

Message: 2 of 4

"Gonzalo " <glpita@gmail.com> wrote in message <htk4jc$4nh$1@fred.mathworks.com>...
> Hi all,
>
> Does anybody know how to generate a series of say 450 non-repeating random integers between 0 and 2000?
>
> Thanks

 p = randperm(2001);
 p = p(1:450)-1;

Roger Stafford

Subject: How to generate non-repeating random integers

From: kk KKsingh

Date: 26 May, 2010 22:03:07

Message: 3 of 4

"Gonzalo " <glpita@gmail.com> wrote in message <htk4jc$4nh$1@fred.mathworks.com>...
> Hi all,
>
> Does anybody know how to generate a series of say 450 non-repeating random integers between 0 and 2000?
>
> Thanks

A SIMPLE SOLUTION
r=randperm(2000);
m=450;
r=r(1:450);

Subject: How to generate non-repeating random integers

From: Gonzalo

Date: 26 May, 2010 22:20:07

Message: 4 of 4

"kk KKsingh" <akikumar1983@gmail.com> wrote in message <htk5qr$nos$1@fred.mathworks.com>...
> "Gonzalo " <glpita@gmail.com> wrote in message <htk4jc$4nh$1@fred.mathworks.com>...
> > Hi all,
> >
> > Does anybody know how to generate a series of say 450 non-repeating random integers between 0 and 2000?
> >
> > Thanks
>
> A SIMPLE SOLUTION
> r=randperm(2000);
> m=450;
> r=r(1:450);

Thanks a lot guys,

Tags for this Thread

No tags are associated with this thread.

What are tags?

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.

Contact us