DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
    • can-construct-super
    • can-define-stream
    • can-fixture
      • types
        • Store
        • ajaxSettings
        • request
        • requestHandler
        • response
      • properties
        • delay
        • on
        • rand
        • store
    • can-fixture-socket
    • can-jquery
    • can-stache-converters
    • can-stream
    • can-vdom
    • can-view-import
    • can-zone
    • steal-stache
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Ecosystem
  • /
  • can-fixture
  • /
  • rand
  • / On this page
    • rand

      function
      • source

      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].

      fixture.rand(1, 10) //-> Random number between 1 and 10 inclusive.
      fixture.rand(10) //-> Random number between 0 and 10 inclusive.
      

      Parameters

      1. min {Number}:

        The lower limit of values that will be returned.

      2. max {Number}:

        The upper limit of values that will be returned. max is valid return value.

      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.

      // pick a random number of items from an array
      fixture.rand(["a","b","c"]) //-> ["c"]
      fixture.rand(["a","b","c"]) //-> ["b","a"]
      
      // pick one item from an array
      fixture.rand(["a","b","c"],1) //-> ["c"]
      
      // get one item from an array
      fixture.rand(["a","b","c"],1)[0] //-> "b"
      
      // get 2 or 3 items from the array
      fixture.rand(["a","b","c"],2,3) //-> ["c","a","b"]
      

      Parameters

      1. choices {Array}:

        An array of values to chose from. The returned array will only include a value once.

      2. min {Number}:

        The minimum number of items to be in the returned array.

      3. max {Number}:

        The maximum number of items in the returned array.

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.