Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Random numer generation without repetition
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Kishore  
View profile  
 More options Apr 25 2009, 4:52 am
Newsgroups: comp.soft-sys.matlab
From: "Kishore " <kishore3...@yahoo.co.in>
Date: Sat, 25 Apr 2009 08:52:02 +0000 (UTC)
Local: Sat, Apr 25 2009 4:52 am
Subject: Random numer generation without repetition
Hi,

I was wondering if it is possible to generate random numbers in the following scenario,

random numbers between  1 to 200, ( i can do it),
but i do not want them to be repeated. for example if i select a sample of 40 elements
it should have random numbers between 1 to 200, but not repeated.

I can use rand function for this, but how can i avoid repetition, by using some modification to this rand () thereby saving some lines of code to check for repetition.

thanks!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dpb  
View profile  
 More options Apr 25 2009, 10:31 am
Newsgroups: comp.soft-sys.matlab
From: dpb <n...@non.net>
Date: Sat, 25 Apr 2009 09:31:20 -0500
Local: Sat, Apr 25 2009 10:31 am
Subject: Re: Random numer generation without repetition

Kishore wrote:
> Hi,

> I was wondering if it is possible to generate random numbers in the following scenario,
> random numbers between  1 to 200, ( i can do it),
> but i do not want them to be repeated. for example if i select a sample of 40 elements
> it should have random numbers between 1 to 200, but not repeated.

> I can use rand function for this, but how can i avoid repetition, by
> using some modification to this rand () thereby saving some lines of
> code to check for repetition....

One way would be with randperm()  (which will use rand() for you)

--


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Fig  
View profile  
 More options Apr 25 2009, 10:40 am
Newsgroups: comp.soft-sys.matlab
From: "Matt Fig" <spama...@yahoo.com>
Date: Sat, 25 Apr 2009 14:40:19 +0000 (UTC)
Local: Sat, Apr 25 2009 10:40 am
Subject: Re: Random numer generation without repetition
Check out randperm.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
uri  
View profile  
 More options Nov 26 2009, 2:25 am
Newsgroups: comp.soft-sys.matlab
From: "uri " <sshango...@hotmail.com>
Date: Thu, 26 Nov 2009 07:25:04 +0000 (UTC)
Local: Thurs, Nov 26 2009 2:25 am
Subject: Re: Random numer generation without repetition

"Matt Fig" <spama...@yahoo.com> wrote in message <gsv7cj$oj...@fred.mathworks.com>...
> Check out randperm.

nice approach but not good enough, I need a small number of elmennts reletively to the maximum sampling size. if I'd use randperm it'll blow my memory

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
TideMan  
View profile  
 More options Nov 26 2009, 2:40 am
Newsgroups: comp.soft-sys.matlab
From: TideMan <mul...@gmail.com>
Date: Wed, 25 Nov 2009 23:40:46 -0800 (PST)
Local: Thurs, Nov 26 2009 2:40 am
Subject: Re: Random numer generation without repetition
On Nov 26, 8:25 pm, "uri " <sshango...@hotmail.com> wrote:

> "Matt Fig" <spama...@yahoo.com> wrote in message <gsv7cj$oj...@fred.mathworks.com>...
> > Check out randperm.

> nice approach but not good enough, I need a small number of elmennts reletively to the maximum sampling size. if I'd use randperm it'll blow my memory

Huh???
tic;y=randperm(200);toc
Elapsed time is 0.001623 seconds.

Did you read the help correctly?
Or is there something that you're not telling us?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
uri  
View profile  
 More options Nov 26 2009, 2:47 am
Newsgroups: comp.soft-sys.matlab
From: "uri " <sshango...@hotmail.com>
Date: Thu, 26 Nov 2009 07:47:03 +0000 (UTC)
Local: Thurs, Nov 26 2009 2:47 am
Subject: Re: Random numer generation without repetition

TideMan <mul...@gmail.com> wrote in message <9983dcb2-dc04-45fe-af74-71e66d7a9...@r24g2000prf.googlegroups.com>...
> On Nov 26, 8:25?pm, "uri " <sshango...@hotmail.com> wrote:
> > "Matt Fig" <spama...@yahoo.com> wrote in message <gsv7cj$oj...@fred.mathworks.com>...
> > > Check out randperm.

> > nice approach but not good enough, I need a small number of elmennts reletively to the maximum sampling size. if I'd use randperm it'll blow my memory

> Huh???
> tic;y=randperm(200);toc
> Elapsed time is 0.001623 seconds.

> Did you read the help correctly?
> Or is there something that you're not telling us?

let's say I have a vector (file wise) on my harddisk which has 10^8 cells
I"d like to sample m elements out of this vector but using:
gen=randperm(10^8);
x=gen(1:m);
gen is too big
I just need the m elements without generating all the 10^8 numbers

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jos (10584)  
View profile  
 More options Nov 26 2009, 3:56 am
Newsgroups: comp.soft-sys.matlab
From: "Jos (10584) " <#10...@fileexchange.com>
Date: Thu, 26 Nov 2009 08:56:02 +0000 (UTC)
Local: Thurs, Nov 26 2009 3:56 am
Subject: Re: Random numer generation without repetition

if m << 10^8 you could just use a simple trial and error approach:

n = 1e8 ;
m = 200;
tic ;
Done = false ;
j = 0 ;
while ~Done,
   j = j + 1 ;
   R = ceil(n*rand(m,1)) ;
   Done = numel(unique(R))==m ;
end
fprintf('\nFound %d unique elements between 1 and %.0e\n   in %.2fs,in %d trial(s)\n',m,n,toc,j) ;

Jos


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John D'Errico  
View profile  
 More options Nov 26 2009, 5:15 am
Newsgroups: comp.soft-sys.matlab
From: "John D'Errico" <woodch...@rochester.rr.com>
Date: Thu, 26 Nov 2009 10:15:07 +0000 (UTC)
Local: Thurs, Nov 26 2009 5:15 am
Subject: Re: Random numer generation without repetition
"Jos (10584) " <#10...@fileexchange.com> wrote in message <helfr2$so...@fred.mathworks.com>...

Exactly. When the sample size is small, just reject
those samples that would have seen a repeat, and
redo the few that fail.

Of course, if the sample size is too large, then this
loop will essentially never terminate. So you need
to be careful there. A simple, lazy, scheme might
use a limit on the number of times the above while
loop will be allowed to run. If it fails without success
after say 5 times, then try a different method to
generate the samples.

John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »