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

W

Wally

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,
 
P

pvdg42

Wally said:
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.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top