mardi 20 janvier 2015

Repeat numbers multiple times when generating multiple numbers

I am trying to generate some numbers but i don't want all of them to be unique.I want if i am generating numbers from 1 to 100 to repeat one number n times.


I have this snippet in mind to make the value of i variable to a number i want repeated,but it can get complicated if i want to repeat another number like 50 and so forth.



for(i = 0; i < 100; i++){
$rand_val = rand(1,100);
if($i = 12)
$rand_val = 40;
}


Is there a random numbers generation class that allows me to generate duplicate and non-duplicate numbers?.





Aucun commentaire:

Enregistrer un commentaire