I have an array of values:
var my_arr = [/*all kinds of stuff*/]
I have a function that generates a random number, which I use as the index of an element in my_arr
...
var RandomFromRange = function (min,max)
{
return Math.floor(Math.random()*(max-min+1)+min);
};
...so I could do stuff like this:
my_arr[RandomFromRange(0,my_arr.length)];
What I want to do is to designate certain elements within my_arr
as having "priority", so that RandomFromRange
returns 5, say, 25% of the time, returns 4, 14% of the time, and returns any other number...
(100 - 25 - 14)/(my_arr.length - 2)
...% of the time.
As I was doing my research, I came across several posts that describe similar problems, but their answers are not in Javascript, and I, alas, don't have enough math to understand their general principles. Any advice would be appreciated.