File tree Expand file tree Collapse file tree 2 files changed +4
-5
lines changed Expand file tree Collapse file tree 2 files changed +4
-5
lines changed Original file line number Diff line number Diff line change 21
21
],
22
22
"dependencies" : {
23
23
"purescript-eff" : " ^0.1.0" ,
24
- "purescript-integers" : " ^0.2.0 " ,
24
+ "purescript-integers" : " ^0.2.1 " ,
25
25
"purescript-math" : " ^0.2.0"
26
26
}
27
27
}
Original file line number Diff line number Diff line change @@ -3,9 +3,7 @@ module Control.Monad.Eff.Random where
3
3
import Prelude
4
4
5
5
import Control.Monad.Eff (Eff ())
6
- import Data.Int (fromNumber , toNumber )
7
-
8
- import qualified Data.Maybe.Unsafe as U
6
+ import Data.Int (fromNumber , toNumber , floor )
9
7
10
8
-- | The `RANDOM` effect indicates that an Eff action may access or modify the
11
9
-- | JavaScript global random number generator, i.e. `Math.random()`.
@@ -28,7 +26,8 @@ foreign import random :: forall e. Eff (random :: RANDOM | e) Number
28
26
randomInt :: forall e . Int -> Int -> Eff (random :: RANDOM | e ) Int
29
27
randomInt low high = do
30
28
n <- random
31
- pure <<< U .fromJust <<< fromNumber <<< Math .floor $ toNumber (high - low + one) * n + toNumber low
29
+ let asNumber = (toNumber high - toNumber low + one) * n + toNumber low
30
+ return $ floor asNumber
32
31
33
32
-- | Returns a random number between a minimum value (inclusive) and a maximum
34
33
-- | value (exclusive). It is unspecified what happens if `maximum < minimum`.
You can’t perform that action at this time.
0 commit comments