mardi 4 juillet 2017

need help on generating a non repeating array

Have a interview quiz lately, and I really struggling here. There are few steps of question, but this final one is making me cracking my brain.

I created 4 set of function mainly is to randomize: 1. alphabet (object_one) 2. integer (object_two) 3. real number (object_three) 4. alphanumerical (object_four)

The final one is to create an random array based on my 4 set of object. Eg: hisadfnnasd, 126263, assfdgsga12348fas, 13123.123,
lizierdjfklaasf, 123192u3kjwekhf, 89181811238,122, nmarcysfa900jkifh , 3.781, 2.11, ....

But this is my code for the final one:

function final_one(min,max,dec){
var obj = [object_one(min,max),object_two(min,max),object_three(min,max,dec),object_four(min,max)]; 
var output = "";
for (var i = 0; i < 10; i++) {
    output += obj[random(0,3)] + ", ";
}
return output;

}

my output will be something like this:

jkwnh1365624sp, 275995, jkwnh1365624sp, 43, jkwnh1365624sp, 275995, 275995, 43, 275995, 275995, 

Data are keep repeating.

Please help!




Aucun commentaire:

Enregistrer un commentaire