vendredi 22 décembre 2017

Randomly find numbers from 1-12 without repeat

I have three variable integers, and I have the following code that randomizes their value:

Randomize()

    number = Int(Rnd() * 12) + 1
    AssignImagesToSquares()

    number2 = Int(Rnd() * 12) + 1
    AssignImagesToSquares()

    number3 = Int(Rnd() * 12) + 1
    AssignImagesToSquares()

And AssignImagesToSquares is a Private Sub where I use them. However, the problem that I am facing is that numbers can be repeated. I could not figure out how to do it, but in psuedocode,

'Randomize the integer "number"

'Randomize the integer "number2" where number2 <> number

'Randomize the integer "number3" where number3 <> number2 <> number.

I thought of maybe using a loop to repeat the process until a match is found but how exactly can that be done?




Aucun commentaire:

Enregistrer un commentaire