Need a sample please...

  • Thread starter Thread starter Goran
  • Start date Start date
G

Goran

Hello,
Does anybody out there have a sample on how to:

1. Get f.eks. 15 random numbers out of 50 but they should be different
numbers ( no two a like)
2. Then sort those numbers from smallest to highest

Thank you
 
Goran said:
Does anybody out there have a sample on how to:

1. Get f.eks. 15 random numbers out of 50 but they should be different
numbers ( no two a like)

Have a look at the documentation for the 'Rnd' function. There you will
find some sample code on how to get a pseudo-random number between two boundaries.
2. Then sort those numbers from smallest to highest

You can add the numbers to an arraylist (or something similar) and sort
them by calling the arraylist's 'Sort' method.
 
Hi Goran,

Put your numbers into an ArrayList. Create an array for your 15 numbers.

To get the first generate a random number from 0 to 49. Use that as an
index into the ArrayList. Copy the value into your array at position 0. Use
ArrayList's RemoveAt method to take that number out of the ArrayList.

To get the second, generate between 0 and 48 (as the ArrayList has
shrunk).

Repeat similarly for the rest.

Regards,
Fergus
 

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

Back
Top