Randomly shuffle a list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vatyk
    New Member
    • Sep 2007
    • 1

    #1

    Randomly shuffle a list

    Hi all,

    I am new, to this forum and also to VB.Net and I encountered a problem. I need an array that contains 100 random numbers, between 1 and 100. More specifically, the array must contain all the numbers between 1 and 100, but in random order, and I don't know how to do that. Any help would be appreciated.

    Thank you.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    One way would be to loop from 1 to 100 and copy each value a randomly-chosen position position in the array. The trick is to keep randomly choosing the position until you find one that contains zero. The most likely way to achieve this is probably with something like a Do loop nested inside a For loop.

    Comment

    Working...