Random.int contains a sanitization step at:
|
( lo, hi ) = |
|
if a < b then |
|
( a, b ) |
|
else |
|
( b, a ) |
As such, Random.int 100 -100 produces values in the range [-100, 100]
Random.float contains no such step, and Random.float 100 -100 produces values in the range [100, 300] due to this, which assumes the bounds were passed in the correct order:
|
-- Scale it into our range |
|
range = |
|
abs (b - a) |
There is no information in the documentation warning of this (otherwise silent) error, and it violates the principle of least surprise.
Either the same sanitization step should be added to Random.float or at the very least a prominent warning should be added to the documentation.
Random.intcontains a sanitization step at:random/src/Random.elm
Lines 81 to 85 in c1c9da4
As such,
Random.int 100 -100produces values in the range[-100, 100]Random.floatcontains no such step, andRandom.float 100 -100produces values in the range[100, 300]due to this, which assumes the bounds were passed in the correct order:random/src/Random.elm
Lines 180 to 182 in c1c9da4
Either the same sanitization step should be added to
Random.floator at the very least a prominent warning should be added to the documentation.