Random numbers select

Discussion in 'ASP General' started by polilop, Nov 13, 2005.

  1. polilop

    polilop Guest

    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??
     
    polilop, Nov 13, 2005
    #1
    1. Advertising

  2. polilop

    Evertjan. Guest

    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.

    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Nov 13, 2005
    #2
    1. Advertising

  3. polilop

    Bob Lehmann Guest

    > 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

    "Evertjan." <> wrote in message
    news:Xns970DE5B2D58E5eejj99@194.109.133.242...
    > 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.
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Replace all crosses with dots in my emailaddress)
    >
     
    Bob Lehmann, Nov 13, 2005
    #3
  4. polilop

    PJones Guest

    PJones, Nov 27, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. globalrev
    Replies:
    4
    Views:
    817
    Gabriel Genellina
    Apr 20, 2008
  2. Alex Untitled
    Replies:
    11
    Views:
    685
    Giampiero Zanchi
    Nov 16, 2009
  3. PerlFAQ Server

    FAQ 4.10 Why aren't my random numbers random?

    PerlFAQ Server, Feb 12, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    234
    PerlFAQ Server
    Feb 12, 2011
  4. PerlFAQ Server

    FAQ 4.10 Why aren't my random numbers random?

    PerlFAQ Server, Apr 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    270
    PerlFAQ Server
    Apr 27, 2011
  5. VK
    Replies:
    15
    Views:
    1,331
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page