Home

function: random


random(lower: number, upper: number, floating: boolean): number

Produces a random number between the inclusive `lower` and `upper` bounds. If only one argument is provided a number between `0` and the given number is returned. If `floating` is `true`, or either `lower` or `upper` are floats, a floating-point number is returned instead of an integer. **Note:** JavaScript follows the IEEE-754 standard for resolving floating-point values which can produce unexpected results.

Example(s):

random(0, 5)
// => an integer between 0 and 5

random(5)
// => also an integer between 0 and 5

random(5, true)
// => a floating-point number between 0 and 5

random(1.2, 5.2)
// => a floating-point number between 1.2 and 5.2

Params:

Name Type Attribute Description
lower The lower bound.
upper The upper bound.
floating Specify returning a floating-point number.

Returns:

number

  {
    "comment": "/**\r\n * Produces a random number between the inclusive `lower` and `upper` bounds.\r\n * If only one argument is provided a number between `0` and the given number\r\n * is returned. If `floating` is `true`, or either `lower` or `upper` are\r\n * floats, a floating-point number is returned instead of an integer.\r\n *\r\n * **Note:** JavaScript follows the IEEE-754 standard for resolving\r\n * floating-point values which can produce unexpected results.\r\n *\r\n * @since 0.7.0\r\n * @category Number\r\n * @param {number} [lower=0] The lower bound.\r\n * @param {number} [upper=1] The upper bound.\r\n * @param {boolean} [floating] Specify returning a floating-point number.\r\n * @returns {number} Returns the random number.\r\n * @see uniqueId\r\n * @example\r\n *\r\n * random(0, 5)\r\n * // => an integer between 0 and 5\r\n *\r\n * random(5)\r\n * // => also an integer between 0 and 5\r\n *\r\n * random(5, true)\r\n * // => a floating-point number between 0 and 5\r\n *\r\n * random(1.2, 5.2)\r\n * // => a floating-point number between 1.2 and 5.2\r\n */",
    "meta": {
        "range": [
            1283,
            2200
        ],
        "filename": "random.js",
        "lineno": 39,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100007315",
            "name": "random",
            "type": "FunctionDeclaration",
            "paramnames": [
                "lower",
                "upper",
                "floating"
            ]
        },
        "vars": {
            "floating": "random~floating",
            "upper": "random~upper",
            "lower": "random~lower",
            "temp": "random~temp",
            "rand": "random~rand",
            "randLength": "random~randLength"
        }
    },
    "description": "Produces a random number between the inclusive `lower` and `upper` bounds.\rIf only one argument is provided a number between `0` and the given number\ris returned. If `floating` is `true`, or either `lower` or `upper` are\rfloats, a floating-point number is returned instead of an integer.\r\r**Note:** JavaScript follows the IEEE-754 standard for resolving\rfloating-point values which can produce unexpected results.",
    "since": "0.7.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Number",
            "value": "Number"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "optional": true,
            "defaultvalue": 0,
            "description": "The lower bound.",
            "name": "lower"
        },
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "optional": true,
            "defaultvalue": 1,
            "description": "The upper bound.",
            "name": "upper"
        },
        {
            "type": {
                "names": [
                    "boolean"
                ]
            },
            "optional": true,
            "description": "Specify returning a floating-point number.",
            "name": "floating"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "description": "Returns the random number."
        }
    ],
    "see": [
        "uniqueId"
    ],
    "examples": [
        "random(0, 5)\r// => an integer between 0 and 5\r\rrandom(5)\r// => also an integer between 0 and 5\r\rrandom(5, true)\r// => a floating-point number between 0 and 5\r\rrandom(1.2, 5.2)\r// => a floating-point number between 1.2 and 5.2"
    ],
    "name": "random",
    "longname": "random",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000667",
    "___s": true,
    "filepath": "random.js"
}