2013-02-04 04:13:08 +00:00
|
|
|
/*! Random
|
|
|
|
!*/
|
2012-10-16 06:03:14 +00:00
|
|
|
|
|
|
|
Elm.Random = function() {
|
2013-02-04 04:13:08 +00:00
|
|
|
/*[In a Range]*/
|
|
|
|
|
|
|
|
/** inRange : Int -> Int -> Signal Int
|
|
|
|
Given a range from low to high, this produces a random number
|
|
|
|
between 'low' and 'high' inclusive. The value in the signal does
|
|
|
|
not change after the page has loaded.
|
|
|
|
**/
|
2012-10-16 06:03:14 +00:00
|
|
|
var inRange = function(min) { return function(max) {
|
|
|
|
return Elm.Signal.constant(Math.floor(Math.random() * (max-min+1)) + min);
|
|
|
|
};
|
|
|
|
};
|
2013-02-04 04:13:08 +00:00
|
|
|
|
|
|
|
/** randomize : Int -> Int -> Signal a -> Signal Int
|
|
|
|
Given a range from low to high and a signal of values, this produces
|
|
|
|
a new signal that changes whenever the input signal changes. The new
|
|
|
|
values are random number between 'low' and 'high' inclusive.
|
|
|
|
**/
|
2012-10-16 06:03:14 +00:00
|
|
|
var randomize = function(min) { return function(max) { return function(signal) {
|
|
|
|
function f(x) { return Math.floor(Math.random() * (max-min+1)) + min; }
|
|
|
|
return Elm.Signal.lift(f)(signal);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return { inRange:inRange, randomize:randomize };
|
|
|
|
}();
|