How can i randomly select from 1-10 with out repeating the same number in the process
-
wrote on 1 Sept 2011, 17:31 last edited by
is there any posible way to control the output of the codes "Math.floor(Math.random()*10+1)" as in everytime it generates a new number it wont generate the same number it previously have. like for example i use math random to generate a question out of 10 questions at first it pick the 3rd question now the next time it will generate another question it will not choose the 3d question again..
-
wrote on 1 Sept 2011, 18:01 last edited by
Hello,
This might help you: "Permutation":http://en.wikipedia.org/wiki/Permutation#Random_generation_of_permutations
-
wrote on 1 Sept 2011, 18:59 last edited by
In other words, no. You will have to add some extra logic to filter out duplicate random numbers.
-
wrote on 2 Sept 2011, 04:44 last edited by
ow i see is it possible to put it somewhere like arrays???
-
wrote on 2 Sept 2011, 06:09 last edited by
Yes. You store indexes of your questions in an array. Than you just get questions[ ramdomized_indexes[ index ] ], where index increases from 0, when user answers a question. ramdomized_indexes is generated when application start.
-
wrote on 2 Sept 2011, 06:24 last edited by
Basically, this is a card shuffling problem. You can google for that, or for "array shuffle".
6/6