Say I'm pseudo-randomly picking a number from 1 to 50 every second for 100 seconds, and as time goes on the number picked is more likely to be greater. How could I structure such an algorithm?
For example: after 99 seconds the probability of choosing a number closer to 50 is much more likely than choosing a number closer to 1.
Or: the number picked after 10 seconds is more likely to be greater than the number picked after 9 seconds
Perhaps the most generic way to do so is called inverse transform sampling: Generate a uniform random number in [0, 1]. Run the quantile function (also known as the inverse CDF or the PPF) on the uniform random number. The result is a random number that fits the distribution.
A random distribution is a set of random numbers that follow a certain probability density function. Probability Density Function: A function that describes a continuous probability. i.e. probability of all values in an array.
There are two types of probability distributions: Discrete probability distributions. Continuous probability distributions.
The probability distribution for a discrete random variable X can be represented by a formula, a table, or a graph, which provides p(x) = P(X=x) for all x. The probability distribution for a discrete random variable assigns nonzero probabilities to only a countable number of distinct x values.
Pick any concave monotonic function like square root which maps 0 to 0 and 1 to 1. Generate a random number between [0,1], apply the function and then scretch [0,1] to the desired interval ([1,50]).
Now if you morph from the linear transformation f(x)=x to the mentioned transform function with for example a simple weighting you have the desired effect.
I have a simple solution for you. Instead of rand(1, 50)
(say this function generates uniformly random numbers 1..50) use this expression:
power(rand(1, power(50, exp)), 1/exp)
this will still give you all the numbers 1..50. For exp = 1
, the distribution will be uniform. As you slightly increase exp (e.g. like 1.1 or so), the probability of getting larger numbers will increase. The higher the exp, the more it will increase towards 50.
So you can do e.g.:
factor = 1 /* finetune this for your needs */
for second = 0..100
exp = 1 + (second / 100) * factor
rand_num = power(rand(1, power(50, exp)), 1/exp)
endfor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With