rand
Returns a random integer.
    fixture.rand(min, max)
  
  Returns a random integer in the range [min, max]. If only one argument is provided,
returns a random integer from [0, max].
import {fixture} from "can";
console.log( fixture.rand( 1, 10 ) ); //-> Random number between 1 and 10 inclusive.
console.log( fixture.rand( 10 ) ); //-> Random number between 0 and 10 inclusive.
Parameters
- min {Number}:The lower limit of values that will be returned. 
- max {Number}:The upper limit of values that will be returned. maxis valid return value.
Returns
 {Number}: 
A number inclusive between min and max.
    fixture.rand(choices, min, max)
  
  An array of between min and max random items from choices. If only min is
provided, max will equal min.  If both max and min are not provided,
min will be 1 and max will be choices.length.
import {fixture} from "can";
// pick a random number of items from an array
console.log( fixture.rand( [ "a", "b", "c" ] ) ); //-> ["c"]
// pick one item from an array
console.log( fixture.rand( [ "a", "b", "c" ], 1 ) ); //-> ["c"]
// get one item from an array
console.log( fixture.rand( [ "a", "b", "c" ], 1 )[ 0 ] ); //-> "b"
// get 2 or 3 items from the array
console.log( fixture.rand( [ "a", "b", "c" ], 2, 3 ) ); //-> ["c","a","b"]
Parameters
- choices {Array}:An array of values to chose from. The returned array will only include a value once. 
- min {Number}:The minimum number of items to be in the returned array. 
- max {Number}:The maximum number of items in the returned array. 
Returns
 {Array}: 
an array between min and max random items from the choices array.
 GitHub
GitHub Twitter
Twitter