Boost logo

Boost :

Subject: Re: [boost] [random][rational] Is there any standard way to generate a random rationals?
From: John Maddock (jz.maddock_at_[hidden])
Date: 2015-03-10 07:37:59

> 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 ...

That not withstanding, the conversion from floating point to rational is
*exact*. So floating point values in the range [1/INT_MAX, INT_MAX]
would map exactly to rational values in that range. Whether they have
the distribution you want is another matter.


Boost list run by bdawes at, gregod at, cpdaniel at, john at