mercredi 18 novembre 2015

Any way to guarantee X amount of a specific number while generating random numbers in a 2D array

I need to fill up a 2D array of size n with random numbers, however I need about n(n-1)/2 * .2 or .4 or .8 of the generated random numbers to be -1 and I need them spread out. Is there any possible way to do this? I thought about while filling up the array every so often make it set that element as -1 and use a count to keep track however there is no way to be sure those -1 are spread apart across the array, is this possible?




Aucun commentaire:

Enregistrer un commentaire