mardi 30 juin 2015

Java - generating random clusters of numbers

I have an array of stuff, and I want to "randomly" select stuff from that array, but I'd like the probability for it to get clusters to be higher.

For example:

arr = [1, 3, 4, 6, 7, 9, 10]
x = Math.random() * arr.length;
return arr[x]

If x came out to be 3, then the function would return 6. How do I increase the likelihood that the next number x will be is 2 or 4 (and then 1 and 5 and so on, with the probability curving the further away it gets from the current x). Is this doable?




Aucun commentaire:

Enregistrer un commentaire