On 12.02.2017 23:14, JiiPee wrote:
> I am trying to get values from the whole : 1 - max(unsigned long long)
> range. But this code (which many recommend on the internet) just does
> not seem to give small number never. the range it produces (128 numbers)
> is always something like:
>
>
> 153348556926869012 - 18291104122139120324
>
> (
>
> 153348556926869012
>
> 18291104122139120324
>
> )
>
> As you can see it keep giving ONLY big numbers. It never give numbers
> like 9887. Why? How can I get values from the whole range? Thanks.
That looks like 64-bit numbers.
Now if you produce 1 such number, the chance of it being less than 2^16
= 65536, a not unreasonable choice for “small” number, is 2^16/2^64 =
2^(16-64) = 2^(-48). The Windows calculator tells me that that is
roughly 3,55 * 10^(-15). Now if you produce 1000 such numbers, the
chance of getting at least one small one, is at most 3,55 * 10^(-12).
More precisely, the chance of not getting any small number among the
1000 numbers is (1 - (3,55 * 10^(-15)))^1000, and correspondingly the
chance of getting at least one, is 1 - (1 - (3,55 * 10^(-15)))^1000. The
Windows calculator says that that is, roughly, 3,55 * 10^(-12). Oh!
Nothing much gained for getting precise here! :)
Cheers & hth.,
- Alf