File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ or if either of `low` or `high` is not an integer.
31
31
32
32
For example:
33
33
``` purescript
34
- randomInt (fromNumber 1) (fromNumber 10) >>= Console.print
34
+ randomInt 1 10 >>= Console.print
35
35
```
36
36
will print a random integer between 1 and 10.
37
37
@@ -46,7 +46,7 @@ value (exclusive). It is unspecified what happens if `maximum < minimum`.
46
46
47
47
For example:
48
48
``` purescript
49
- randomRange 1 2 >>= Console.print
49
+ randomRange 1.0 2.0 >>= Console.print
50
50
```
51
51
will print a random number between 1 and 2.
52
52
Original file line number Diff line number Diff line change @@ -22,24 +22,26 @@ foreign import random :: forall e. Eff (random :: RANDOM | e) Number
22
22
-- |
23
23
-- | For example:
24
24
-- | ``` purescript
25
- -- | randomInt (fromNumber 1) (fromNumber 10) >>= Console.print
25
+ -- | randomInt 1 10 >>= Console.print
26
26
-- | ```
27
27
-- | will print a random integer between 1 and 10.
28
28
randomInt :: forall e . Int -> Int -> Eff (random :: RANDOM | e ) Int
29
29
randomInt low high = do
30
30
n <- random
31
- pure <<< U .fromJust <<< fromNumber <<< Math .floor $ toNumber (( high - low + one) + low) * n
31
+ pure <<< U .fromJust <<< fromNumber <<< Math .floor $ toNumber (high - low + one) * n + toNumber low
32
32
33
33
-- | Returns a random number between a minimum value (inclusive) and a maximum
34
34
-- | value (exclusive). It is unspecified what happens if `maximum < minimum`.
35
35
-- |
36
36
-- | For example:
37
37
-- | ``` purescript
38
- -- | randomRange 1 2 >>= Console.print
38
+ -- | randomRange 1.0 2.0 >>= Console.print
39
39
-- | ```
40
40
-- | will print a random number between 1 and 2.
41
41
randomRange :: forall e . Number -> Number -> Eff (random :: RANDOM | e ) Number
42
- randomRange min max = (((max - min) + min) *) <$> random
42
+ randomRange min max = do
43
+ n <- random
44
+ return (n * (max - min) + min)
43
45
44
46
-- | Returns a random boolean value with an equal chance of being `true` or
45
47
-- | `false`.
You can’t perform that action at this time.
0 commit comments