Skip to content

Commit

Permalink
fixes elm#21
Browse files Browse the repository at this point in the history
fixes elm#22

Sanitize input to `float` to avoid invalid values
  • Loading branch information
SiriusStarr authored and rupertlssmith committed Feb 17, 2023
1 parent c1c9da4 commit 0b9ad8b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Random.elm
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ float : Float -> Float -> Generator Float
float a b =
Generator (\seed0 ->
let
-- Sanitize the input range
( minRange, maxRange ) =
if a < b then
( a, b )
else
( b, a )

-- Get 64 bits of randomness
seed1 =
next seed0
Expand All @@ -179,10 +186,10 @@ float a b =

-- Scale it into our range
range =
abs (b - a)
abs (maxRange - minRange)

scaled =
val * range + a
val * range + minRange
in
( scaled, next seed1 )
)
Expand Down

0 comments on commit 0b9ad8b

Please sign in to comment.