-
Just testing the float and double arbs, using sample, like so:
The numbers are clustered very, very, very tightly next to the min and max, which wasn't what I was expecting. I was expecting a more or less flat distribution. Is this expected behavior? Including a histogram. Edit to add some additional notes: There is a noBias() method which on the integer arb will generate a flat distribution, but on the double arb generates a distribution that is clustered entirely around min. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The current implementation of That's said, if you want a more uniform distribution for the value you might want to rely on something like: |
Beta Was this translation helpful? Give feedback.
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 orfc.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.