jeudi 19 février 2015

Random generate three integer values and check if they are unique

First, I am generating random integer values to get some values to check.



var A1, B2, C3:int;
A1 = Math.random() * 100 + 1;
B2 = Math.random() * 100 + 1;
C3 = Math.random() * 100 + 1;


Then I want to check if all the variables are unique from each other.



if (!(A1 == B2 || A1 == C3 || B2 == C3)){
unique = true;
}else{ // Not unique
}


If the variables are not unique to each other, I want to keep only the value for A1, and then change the two other variables B2 and C3 and then again check if they are unique.



}else{ // Not unique
if (unique = false){
do{
B2 = Math.random() * A1 + 1;
C3 = Math.random() * A1 + 1;

if (!(A1 == B2 || A1 == C3 || B2 == C3)){
unique = true;
}while (unique = true)
}
trace("Not unique");
}


My problem is that I cannot get three unique values, and any help on how I can solve this is highly appreciated.





Aucun commentaire:

Enregistrer un commentaire