Random Number Generating

Discussion in 'ASP .Net' started by Leon, Oct 18, 2004.

  1. Leon

    Leon Guest

    I need a program that generate 5 non-duplicates random number between 1-10
    as string values store in an array.

    Do anybody know of any good books or websites that explain how to generator
    random numbers using asp.net?

    Plus If you have any coding practice ideas for the above defined project
    please share them.

    Thanks!
    Leon, Oct 18, 2004
    #1
    1. Advertising

  2. Look at the Random class.
    =?Utf-8?B?U2NvdHQgU2ltb25z?=, Oct 18, 2004
    #2
    1. Advertising

  3. Leon wrote:
    > I need a program that generate 5 non-duplicates random number between 1-10
    > as string values store in an array.
    >
    > Do anybody know of any good books or websites that explain how to generator
    > random numbers using asp.net?


    Leon, in .NET you can use the Random class to generate a random number.
    See the technical docs at http://tinyurl.com/5b8m4

    For your particular problem I'd do the following:

    (1) Create an ArrayList with 10 elements, the numbers 1 through 10
    (2) In a for loop that iterates 5 times, randomly choose a number, n,
    between 1 and the size of the ArrayList.
    (3) Your randomly chosen number is the number at element n in the
    ArrayList. Remove this element from the ArrayList and go back to step (2).

    This approach guarantees you 5 unique random numbers with 5 tries. hth

    --

    Scott Mitchell

    http://www.4GuysFromRolla.com

    * When you think ASP.NET, think 4GuysFromRolla.com!
    Scott Mitchell [MVP], Oct 18, 2004
    #3
  4. See the following URL:

    http://msdn.microsoft.com/library/d...us/cpref/html/frlrfSystemRandomClassTopic.asp

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    I get paid good money to
    solve puzzles for a living

    "Leon" <> wrote in message
    news:...
    > I need a program that generate 5 non-duplicates random number between 1-10
    > as string values store in an array.
    >
    > Do anybody know of any good books or websites that explain how to

    generator
    > random numbers using asp.net?
    >
    > Plus If you have any coding practice ideas for the above defined project
    > please share them.
    >
    > Thanks!
    >
    >
    Kevin Spencer, Oct 18, 2004
    #4
  5. Leon

    Patrice Guest

    See System.Math.Random in the class documentation (though I don't know if a
    number is really "random" if you require it not to be the same than a
    previous number).

    You could have an array that tells if this partiuclar number is already
    taken allowing to pick a new random number. You could use use a list if you
    have a bigger interval (so that you can browse already picked numbers rather
    than to have a boolean for each possible number).

    Patrice

    --

    "Leon" <> a écrit dans le message de
    news:...
    > I need a program that generate 5 non-duplicates random number between 1-10
    > as string values store in an array.
    >
    > Do anybody know of any good books or websites that explain how to

    generator
    > random numbers using asp.net?
    >
    > Plus If you have any coding practice ideas for the above defined project
    > please share them.
    >
    > Thanks!
    >
    >
    Patrice, Oct 18, 2004
    #5
  6. Leon

    Leon Guest

    I want to thank all you guys for your responses! But out all the responses
    which is the best way to solve my problem?

    "Kevin Spencer" <> wrote in message
    news:...
    > See the following URL:
    >
    > http://msdn.microsoft.com/library/d...us/cpref/html/frlrfSystemRandomClassTopic.asp
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > I get paid good money to
    > solve puzzles for a living
    >
    > "Leon" <> wrote in message
    > news:...
    >> I need a program that generate 5 non-duplicates random number between
    >> 1-10
    >> as string values store in an array.
    >>
    >> Do anybody know of any good books or websites that explain how to

    > generator
    >> random numbers using asp.net?
    >>
    >> Plus If you have any coding practice ideas for the above defined project
    >> please share them.
    >>
    >> Thanks!
    >>
    >>

    >
    >
    Leon, Oct 18, 2004
    #6
  7. > I want to thank all you guys for your responses! But out all the responses
    > which is the best way to solve my problem?


    Why, Leon, you needn't ask:

    http://msdn.microsoft.com/library/d...us/cpref/html/frlrfSystemRandomClassTopic.asp

    Microsoft, after all, DID write the "book" on .Net. That is a page from it.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    I get paid good money to
    solve puzzles for a living

    "Leon" <> wrote in message
    news:...
    > I want to thank all you guys for your responses! But out all the responses
    > which is the best way to solve my problem?
    >
    > "Kevin Spencer" <> wrote in message
    > news:...
    > > See the following URL:
    > >
    > >

    http://msdn.microsoft.com/library/d...us/cpref/html/frlrfSystemRandomClassTopic.asp
    > >
    > > --
    > > HTH,
    > > Kevin Spencer
    > > .Net Developer
    > > Microsoft MVP
    > > I get paid good money to
    > > solve puzzles for a living
    > >
    > > "Leon" <> wrote in message
    > > news:...
    > >> I need a program that generate 5 non-duplicates random number between
    > >> 1-10
    > >> as string values store in an array.
    > >>
    > >> Do anybody know of any good books or websites that explain how to

    > > generator
    > >> random numbers using asp.net?
    > >>
    > >> Plus If you have any coding practice ideas for the above defined

    project
    > >> please share them.
    > >>
    > >> Thanks!
    > >>
    > >>

    > >
    > >

    >
    >
    Kevin Spencer, Oct 18, 2004
    #7
    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. Wally
    Replies:
    1
    Views:
    2,778
    pvdg42
    Mar 20, 2006
  2. John Tsiombikas (Nuclear / the Lab)

    Re: Generating a random number

    John Tsiombikas (Nuclear / the Lab), Jul 1, 2003, in forum: C++
    Replies:
    1
    Views:
    351
    David White
    Jul 1, 2003
  3. Marco de Boer

    Re: Generating a random number

    Marco de Boer, Jul 1, 2003, in forum: C++
    Replies:
    1
    Views:
    557
    J. Campbell
    Jul 2, 2003
  4. globalrev
    Replies:
    4
    Views:
    745
    Gabriel Genellina
    Apr 20, 2008
  5. VK
    Replies:
    15
    Views:
    1,125
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page