The Pareto Distribution is a probability distribution that comes up a lot in nature. It has lots of special properties, such as an infinite mean. In this challenge, you will output a number sampled from this distribution.
The Pareto Distribution is defined to be greater than or equal to
x with probability
1/x, for all
x greater than or equal to 1.
Therefore, a number sampled from this distribution is greater than or equal to 1 with probability 1, greater than or equal to 2 with probability exactly 1/2, greater than or equal to 3 with probability exactly 1/3, greater than or equal to 11.4 with probability exactly 1/11.4, and so on.
Since you will sample this distribution, your program or function will take no input, and output a random number, with the above probabilities. However, if your program doesn't perfectly match the above probabilities due to floating-point impression, that's OK. See the bottom of the challenge for more details.
(This is called the Pareto Distribution with alpha 1 and lower bound 1, to be exact)
Here's 10 example draws from this distribution:
1.1540029602790338 52.86156818209856 3.003306506971116 1.4875532217142287 1.3604286212876546 57.5263129600285 1.3139866916055676 20.25125817471419 2.8105749663695208 1.1528212409680156
Notice how 5 of them are below 2, and 5 are above 2. Since this is the average result, it could have been higher or lower, of course.
Your answer only needs to be correct up to the limits of your floating point type, real number type, or whatever else you use, but you must be able to represent numbers at at least 3 decimal digits of precision, and represent numbers up to 1,000,000. If you're not sure whether something is OK, feel free to ask.
This is code golf.
Details about imprecision:
For each range
[a, b], where
1 <= a < b, the ideal probability that the sample would fall in that range is
1/a - 1/b. The probability that your program produces a number in that range must be with
1/a - 1/b. If
Xis the output of your program, it is required that
|P(a <= X <= b) - (1/a - 1/b)| < 0.001.
Note that by applying the above rule with
bsufficiently large, it is the case that your program must output a number greater than or equal to 1 with at least probability 0.999. The rest of the time it may crash, output
Infinity, or do whatever else.
I'm fairly certain that the existing submissions of the form
x is a random float in
[0, 1) or
(0, 1) or
[0, 1], all satisfy this requirement.