Answer the question
In order to leave comments, you need to log in
Random number with given probability, what algorithm?
We need an algorithm, or at least a prerequisite for it
Purpose:
given from 0 to N numbers, N can be 3-20
at the output we get a random number in a given range, and if we do
1000 iterations, we get that there are many numbers closer to 0 times more numbers that lie closer to N.
for example, from 0 to 8
, then with 100 or 1000 iterations we get:
0 - 22%
1- 19%
2 - 16%
3 - 13%
4 - 10%
5 - 8%
6 - 6%
7 - 4%
8 - 2%
*numbers are approximate, only to convey the essence of the idea
Answer the question
In order to leave comments, you need to log in
Make a long range, made up of segments proportional to the probabilities.
0..22 : "0"
22..22+19=41: "1"
41..41+16=57: "2"
...
..100: "8"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question