I currently need a function that
- given access to (enough) uniformly distributed (pseudo)random bits,
- choose a random value from a continuous uniform distribution within a given range (including the full range of finite
Float
values), and then convert that value to the nearest representableFloat
value. Depending on the size and span of range, some concrete values may be represented more frequently than others, but anyFloat
value within the range can be returned.
And since that's the goal stated in the documentation for Float.random(in:using:)
, but not exactly what it currently does, and:
I wonder if there's a working updated implementation somewhere that I can look at?
If not (and unless it won't be within days) I'd just like to know if anyone can give me some pointers as to how this function could/should work (roughly), because I might try to implement it myself, just to cover my immediate needs*, ie not for the stdlib.
I can post any possibly resulting code here though, should anyone be interested in giving it a critical eye or so.
Here's an example of a related paper I found.
* My immediate needs has to do with (reproducible) testing, mainly geometry, image processing and physics code. I use a small custom pseudorandom API and not the one in the stdlib, because I need full control over its operation and efficiency.