I need an 2d array [9,16] with 144 numbers from 1->36 in random order (so each number is repeated 4 times).
3 Answers
Something like:
sourcearr = array();
for(i = 0; i < 36; i++){
for(j = 0; j < 4; j++){
sourcearr[i+j] = i;
}
}
sourcearr = shuffle(sourcearr)
k = 0;
myrandarr = array();
for(i = 0; i < 9; i++){
myrandarr[i] = array();
for(j = 0; j < 16; j++){
myrandarr[i][j] = sourcearr[k++];
}
}
where you use shuffle.
2 Comments
A New Chicken
I forgot to say that each number is repeated 4 times, it isn't just random.
A New Chicken
So there is nothing such as: Enumerable.Range(1,36)?
Assuming you don't care about the distribution, just store the results of
Math.floor(Math.random()*36) + 1
for each element of the array
1 Comment
Jerod Venema
This won't repeat each number 4 times however.