Probability distribution of probable random numbers

Let's say that I pseudo-randomly select a number from 1 to 50 seconds every second for 100 seconds, and as soon as the time is typed, the number will be larger. 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 close to 1.

Or: the number selected after 10 seconds is more likely to be larger than the number selected after 9 seconds.

+6
source share
4 answers

I have a simple solution for you. Instead of rand(1, 50) (let's say this function generates evenly random numbers 1..50), use this expression:

 power(rand(1, power(50, exp)), 1/exp) 

it will still give you all the numbers 1.50. For exp = 1 distribution will be uniform. As you slightly increase exp (e.g., about 1.1 or so), the likelihood of getting large numbers will increase. The higher the exp value, the more it will increase to 50.

So you can do, for example:

 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 
+4
source

Select any concave monotone function, such as the square root, that displays from 0 to 0 and from 1 to 1. Create a random number between [0,1], apply this function and then scroll [0,1] to the desired interval ( [1, 50]).

Now, if you go from the linear transformation f (x) = x to the mentioned transformation function, for example, simple weighting, you will get the desired effect.

+5
source

pseudo code:

 let i = 0 let n = 50 // Adjust for your needs for i goes to 100 { randomnum = int(sqrt(rand(1, 50*n))); } 

It can be very straightforward, but it is one way to get closer to it.

Thanks to Ricky Bobby for pointing out a fundamental problem with my old approach. This is inspired by yi_H's suggestion to use a function like sqrt.

+1
source

There are probably simpler ways for what you are doing, but the general solution is to use inverse transform sampling .

Essentially, if you want to create a random number with a given PDF, p (x), you first compute the inverse total density function (CDF), P '(x). You can then generate uniform random numbers between 0 and 1, and then apply P '(x) to them.

0
source

Source: https://habr.com/ru/post/894948/


All Articles