On Mar 10, 2015, at 11:29 AM, MJanes
wrote: Il giorno martedì 10 marzo 2015 11:14:26 UTC+1, Thorsten Ottosen ha scritto:
Given a random double in some interval, would it be possible to calculate the nearest rational number?
there's no nearest rational number, as there are inifinetly many of them in any bounded neighbourhood of any real number. Unless by nearest you mean the nearest rational with the greatest representable denominator... but in this case the result will not be uniform anymore. As said, uniformity ( meaning prob(x in [a,b])=b-a ) seems fundamentally impossible for rationals for the aforementioned reasons …
Yes, probably for my particular case, the best I can get is a random integer for numerator after fixing the denominator in some number. Making it be in [0-1] will be equivalent to make it between 0 and numerator in that case. Thanks for the comments.