UNPKG

1.56 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function random
4
5Return a random number larger or equal to `min` and smaller than `max`
6using a uniform distribution.
7
8
9## Syntax
10
11```js
12math.random() // generate a random number between 0 and 1
13math.random(max) // generate a random number between 0 and max
14math.random(min, max) // generate a random number between min and max
15math.random(size) // generate a matrix with random numbers between 0 and 1
16math.random(size, max) // generate a matrix with random numbers between 0 and max
17math.random(size, min, max) // generate a matrix with random numbers between min and max
18```
19
20### Parameters
21
22Parameter | Type | Description
23--------- | ---- | -----------
24`size` | Array &#124; Matrix | If provided, an array or matrix with given size and filled with random values is returned
25`min` | number | Minimum boundary for the random value, included
26`max` | number | Maximum boundary for the random value, excluded
27
28### Returns
29
30Type | Description
31---- | -----------
32number &#124; Array &#124; Matrix | A random number
33
34
35## Examples
36
37```js
38math.random() // returns a random number between 0 and 1
39math.random(100) // returns a random number between 0 and 100
40math.random(30, 40) // returns a random number between 30 and 40
41math.random([2, 3]) // returns a 2x3 matrix with random numbers between 0 and 1
42```
43
44
45## See also
46
47[randomInt](randomInt.md),
48[pickRandom](pickRandom.md)