Generate Random Numbers

1. aniket Guest

## Generate Random Numbers

Please help !!!<BR><BR>I want to generate 10 unique randoem numbers within 1 to 20.<BR><BR>I used randomise with rnd() function, but it reapeats atleast two numbers in the set of 10. I want all the 10 numbers to be unique. No problem if the number in the previos set is reapeated in the next set of 10 numbers. But in the same set there should not be any repeatation of numbers.<BR><BR>Please tell me how it can be accomplished.<BR><BR>Below is the code i had been using.<BR><BR>for j=0 to 9<BR>randomize<BR>i = int((20*rnd)+1)<BR>sarray(j) = i<BR>next<BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Rule 1...

...read the ASPFAQs.<BR><BR>http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=114<BR><BR>If you just use ShuffleDeck with a deck size of 20 and then grab the first 10 elements of the array that you get back, that will do the job, won&#039;t it?

3. aniket Guest

## RE: Rule 1...

thanks very much.<BR>

4. Kezia Guest

## RE: Generate Random Numbers

&nbsp;<BR>I would use something like this:<BR><BR>for j=0 to 9 <BR> sarray(j)=0<BR>next<BR><BR>for j=0 to 9 <BR> do<BR> randomize <BR> i = int((20*rnd)+1) <BR> loop while i=sarray(0) or i=sarray(1) or i=sarray(2) or <BR>i=sarray(3) or i=sarray(4) or i=sarray(5) or i=sarray(6) or i=sarray(7) or i=sarray(8) or i=sarray(9) <BR><BR> sarray(j) = i <BR>next <BR><BR>Hope this helps,<BR><BR>K

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•