1 |
|
2 |
|
3 | # Function random
|
4 |
|
5 | Return a random number larger or equal to `min` and smaller than `max`
|
6 | using a uniform distribution.
|
7 |
|
8 |
|
9 | ## Syntax
|
10 |
|
11 | ```js
|
12 | math.random() // generate a random number between 0 and 1
|
13 | math.random(max) // generate a random number between 0 and max
|
14 | math.random(min, max) // generate a random number between min and max
|
15 | math.random(size) // generate a matrix with random numbers between 0 and 1
|
16 | math.random(size, max) // generate a matrix with random numbers between 0 and max
|
17 | math.random(size, min, max) // generate a matrix with random numbers between min and max
|
18 | ```
|
19 |
|
20 | ### Parameters
|
21 |
|
22 | Parameter | Type | Description
|
23 | --------- | ---- | -----------
|
24 | `size` | Array | 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 |
|
30 | Type | Description
|
31 | ---- | -----------
|
32 | number | Array | Matrix | A random number
|
33 |
|
34 |
|
35 | ## Examples
|
36 |
|
37 | ```js
|
38 | math.random() // returns a random number between 0 and 1
|
39 | math.random(100) // returns a random number between 0 and 100
|
40 | math.random(30, 40) // returns a random number between 30 and 40
|
41 | math.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)
|