If i wanted to generate an array that contains 16 numbers (from 0 to 15 inclusive) but i wanted the 16 numbers to be arranged in the array randomly.
e.g. 0,3,9,1,2,15,12 etc
how would i go about doing this. i have been told that:
[CODE]
var randomNumber = 0;
for (var k = 0; k <= 16; k++)
{
randomNumber = Math.floor(1 + Math.random() * 15);
numbers[k] = numbers[randomNumber];
}
// numbers is an array containing 16 positions (they must be WHOLE integers)
the code above would work, but any fool can see the faults in that. my tutor said that this would work because the possibility of the same number occuring twice would be slim, well i can assure you on every trial i have done i have had 4 or more of the same number appear.
Please help, would i have to use two arrays numbers[] and a temp array, and then check every single number as it is sent through to see if it has been used of not?
please help
Cheers
?
dkeegh