0

I've got this thing that has kept me puzzling for a few days now.
I've created an array of 30 integers, randomly chosen.
I would like to add the integers randomly to a two-dimensional array of 12 x 12 integers.
The remaining elements in the two-dimensional array should keep their null value.
I have no clue about how to get these integers randomly into the two-dimensional array, though.
Any wizzards here who would like to help me out ?

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Rashakil Fol
0

Look up "random shuffle" algorithms.

The way it works is that you fill the array with N values, and then you pick which value should go last, picking a number from 0 to N-1. Then swap that value with the one in the last position. Then pick a value which should go second-last (choosing a number from 0 to N-2). Then swap that value with the one in the second-last position. Then pick... and so on.

This gives each possible permutation an equal probability of being chosen. (In particular, there are N! permutations of N elements, and there are N! combinations of random numbers you picked, which makes sense.)

Specifically that picks permutations randomly [i]and[/i] uniformly.

Another technique, which is broken, is "for i = 0 to N-1, pick a random element from a position chosen from 0 to N-1 and swap it with the i'th element." That would give some permutations a better chance of being chosen than others.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.