Random numbers select

P

polilop

I have 30 numbers. I need to select randomly 10 out of the given 30. A
number must not repeat ( eg. i can't have number 10 twice ). How can i do
this??
 
E

Evertjan.

polilop wrote on 13 nov 2005 in microsoft.public.inetserver.asp.general:
I have 30 numbers. I need to select randomly 10 out of the given 30. A
number must not repeat ( eg. i can't have number 10 twice ). How can i
do this??

Fill an array with thos numbers and randomly select from tha array,
emptying the taken places.

If the next selection is empty, try again.

Show your code, if it does not work.
 
B

Bob Lehmann

If the next selection is empty, try again.
This can be extremely slow, especially as the number of already selected
items grows.

The typical shuffle algorithim selects an item from the array between 0 and
the upper bound of the array, moves it the end of the array, or removes it
altogether, then selects the next item from from the array with a range
between 0 and the upper bound of the array - 1.

Here's a VBScript example -
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=114

Bob Lehmann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top