Demo of how you can generate random numbers based on a set of given probabilities for a range of numbers.
Probabilites (key is number, value is number's probability)
{ 2, 0.005 },
{ 3, 0.4 },
{ 4, 0.5 },
Result (the first object shows how many numbers and the second object shows their percentage)
{
"0": 1355,
"1": 1331,
"2": 485,
"3": 39896,
"4": 49978,
"5": 1414,
"6": 1384,
"7": 1388,
"8": 1385,
"9": 1384
}
{
"0": 0.01355,
"1": 0.01331,
"2": 0.00485,
"3": 0.39896,
"4": 0.49978,
"5": 0.01414,
"6": 0.01384,
"7": 0.01388,
"8": 0.01385,
"9": 0.01384
}