on d9d1dfd help sign in
elk/core-js/Signal/Random.js
29 lines 996 B history raw
1/*! Random
2 !*/
4Elm.Random = function() {
5 /*[In a Range]*/
7 /** inRange : Int -> Int -> Signal Int
8 Given a range from low to high, this produces a random number
9 between 'low' and 'high' inclusive. The value in the signal does
10 not change after the page has loaded.
11 **/
12 var inRange = function(min) { return function(max) {
13 return Elm.Signal.constant(Math.floor(Math.random() * (max-min+1)) + min);
14 };
15 };
17 /** randomize : Int -> Int -> Signal a -> Signal Int
18 Given a range from low to high and a signal of values, this produces
19 a new signal that changes whenever the input signal changes. The new
20 values are random number between 'low' and 'high' inclusive.
21 **/
22 var randomize = function(min) { return function(max) { return function(signal) {
23 function f(x) { return Math.floor(Math.random() * (max-min+1)) + min; }
24 return Elm.Signal.lift(f)(signal);
25 };
26 };
27 };
28 return { inRange:inRange, randomize:randomize };
29}();