Random number generator, generating 10 different numbers. Need Help.

Discussion in 'ASP .Net' started by Wally, Mar 19, 2006.

  1. Wally

    Wally Guest

    I am after VB.net code for a random number generator that will generate 10
    different numbers between 1 and 10 and put them into an array. For example I
    want the output to be something like 10,7,8,6,9,4,5,2,3,1.

    Can anyone provide me with the code?

    Thanks,
     
    Wally, Mar 19, 2006
    #1
    1. Advertising

  2. Wally

    pvdg42 Guest

    "Wally" <> wrote in message
    news:_WlTf.226831$...
    >I am after VB.net code for a random number generator that will generate 10
    >different numbers between 1 and 10 and put them into an array. For example
    >I want the output to be something like 10,7,8,6,9,4,5,2,3,1.
    >
    > Can anyone provide me with the code?
    >
    > Thanks,
    >

    Here is code to generate numbers using the Random class:

    Dim rx As New Random

    Dim intArray() As Integer = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

    Dim i As Integer = 0

    While i < 10

    intArray(i) = rx.Next(1, 11)

    i += 1

    End While

    Note that there is no guarantee that each number will be unique, as
    randomness implies possible duplication. To generate unique numbers, you
    would have to add logic to test each new candidate entry for the array to
    ensure it had not already been entered.
     
    pvdg42, Mar 20, 2006
    #2
    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. Replies:
    3
    Views:
    12,550
    Boris Stumm
    Feb 9, 2006
  2. lallous
    Replies:
    5
    Views:
    580
    lallous
    Oct 20, 2003
  3. sugaray

    problem with generating random numbers !

    sugaray, Sep 13, 2003, in forum: C Programming
    Replies:
    2
    Views:
    392
    Tom Zych
    Sep 14, 2003
  4. Intaek LIM
    Replies:
    1
    Views:
    418
    Andreas Kahari
    Oct 31, 2003
  5. Alex Untitled
    Replies:
    11
    Views:
    661
    Giampiero Zanchi
    Nov 16, 2009
Loading...

Share This Page