Skip to content

double distribution is bimodal and mostly empty #4328

Answered by dubzzz
acthp asked this question in Q&A
Discussion options

You must be logged in to vote

The current implementation of double is uniform on the set of available values. The reason why it mostly generates values close to zero is that there are far more values in [0,1[ than in [1,2[ for a double.

That's said, if you want a more uniform distribution for the value you might want to rely on something like: fc.integer({ min: 0, max: (1 << 24) - 1 }).map((v) => v / (1 << 24)) for f32 floats or fc.tuple(fc.integer({ min: 0, max: (1 << 26) - 1 }), fc.integer({ min: 0, max: (1 << 27) - 1 })).map((v) => (v[0] * Math.pow(2, 27) + v[1]) * Math.pow(2, -53)) for f64 floats.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dubzzz
Comment options

Answer selected by dubzzz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants