rand

  • function
can.fixture.rand  

Create a random number or selection.

can.fixture.rand([min,] max)

Parameters

  1. min=0 {Number}Optional

    The lower bound on integers to select.

  2. max {Number}

    The upper bound on integers to select.

Returns

{Number}

A random integer in the range [min, max).

can.fixture.rand(choices, min[ ,max])

Parameters

  1. choices {Array}

    An array of things to choose from.

  2. min {Number}

    The minimum number of times to choose from choices.

  3. max=min {Number}Optional

    The maximum number of times to choose from choices.

Returns

{Array}

An array of between min and max random choices from choices.

can.fixture.rand creates random integers or random arrays of other arrays.

Examples

var rand = can.fixture.rand;

// get a random integer between 0 and 10 (inclusive)
rand(11);

// get a random number between -5 and 5 (inclusive)
rand(-5, 6);

// pick a random item from an array
rand(["j","m","v","c"],1)[0]

// pick a random number of items from an array
rand(["j","m","v","c"])

// pick 2 items from an array
rand(["j","m","v","c"],2)

// pick between 2 and 3 items at random
rand(["j","m","v","c"],2,3)