I’m trying to implement a probability distribution function in java where it returns the ith entry in the array with probability:
Fi = 6i(n-i) / (n3 - n)
where n is the array length i.e. for an array length 4:
P1 = 3/10, P2 = 4/10, P3 = 3/10, P4 = 0
Note that this function assumes numbering from 1 to n rather 0 to n-1 as in Java.
At the moment I’m just using the uniform distribution i.e.
int i = (int)(Math.random()*((arraySize)-1));
with the -1 so it doesn’t choose the last element (i.e. Pn = 0 as in the above formula).
Anyone with any ideas or tips on implementing this?
1 Answer