I ran into the same problem and came up with some simple solution. Not perfect, but suitable for some occasions.
You have an array with some numbers [1,2,3, ...], and you need to select a value with some probability [10,5,20, ...], just create a new array and repeat each value as much times more likely for example
arr[] = [1,1,1,1,...(10 times),2,2,2,..(5 times),3,3,3,3,...(20 times)];
And they just get a random number from 0 to the new array length and get your value with the number with the desired probability.
int r = Random(0,arr.count); int value = arr[r];
As I mentioned, it is not perfect, nor is it an efficient memory algorithm, but it works.
Artem source share