Due to finite precision of number representations, we face situations like:
In: 0.1+0.1+0.1==0.3
Out: False
(on my machine, with Python 2.7 and Python 3 but this is not directly related to the language actually).
This is because there is just no exact representation of $0.1$ (for instance) in typical float formats:
In: "%f"%0.1
Out: '0.1'
In: "%.20f"%0.1
Out: '0.10000000000000000555'
If I understand correctly, this means that several decimal numbers may have the exact same internal representation, even with a finite number of decimals. This is true for instance with the decimal number $0.1$ and the one equal to the internal representation of $0.1$, as illustrated above.
Then, the standard practice that consists in sampling random decimal numbers by sampling integers and rescaling them raises questions: it seems to me that the obtained sample may not be uniformly distributed, even if the integer sampling is uniform. Worse, some decimals in the target set may never appear.
Indeed, a decimal number may be obtained from several integers. For instance, I may sample decimal numbers between $0$ and $1$ with $20$ digits precision by sampling integers between $0$ and $10^{20}$ and take their inverses with $20$ decimals. But, as shown above, the integers $10^{19}$ and $10^{19}+555$ lead to the same $20$ digit precision decimal number (on my machine). On the countrary, I cannot sample $0.10000000000000000000$ in this way.
Am I right?
Does anyone know any concrete situation where this may be a serious issue?
With all this in mind, I am having trouble understanding what generating a random float number between 0 and 1 even means, to mention only one of many such claims. It seems to me that such generators cannot generate $0.1$, which actually is not a float number (on my machine)... Does this mean that we sample a uniformly random decimal number among the ones that have an exact internal representation?
In my understanding, all the above means that, when uniformity is crucial, we should only work with integer or string representations of decimal number. Are there better ways?