1 |
|
2 |
|
3 | function factory (type, config, load, typed) {
|
4 | const distribution = load(require('./distribution'))
|
5 |
|
6 | /**
|
7 | * Return a random integer number larger or equal to `min` and smaller than `max`
|
8 | * using a uniform distribution.
|
9 | *
|
10 | * Syntax:
|
11 | *
|
12 | * math.randomInt(max) // generate a random integer between 0 and max
|
13 | * math.randomInt(min, max) // generate a random integer between min and max
|
14 | * math.randomInt(size) // generate a matrix with random integer between 0 and 1
|
15 | * math.randomInt(size, max) // generate a matrix with random integer between 0 and max
|
16 | * math.randomInt(size, min, max) // generate a matrix with random integer between min and max
|
17 | *
|
18 | * Examples:
|
19 | *
|
20 | * math.randomInt(100) // returns a random integer between 0 and 100
|
21 | * math.randomInt(30, 40) // returns a random integer between 30 and 40
|
22 | * math.randomInt([2, 3]) // returns a 2x3 matrix with random integers between 0 and 1
|
23 | *
|
24 | * See also:
|
25 | *
|
26 | * random, pickRandom
|
27 | *
|
28 | * @param {Array | Matrix} [size] If provided, an array or matrix with given
|
29 | * size and filled with random values is returned
|
30 | * @param {number} [min] Minimum boundary for the random value, included
|
31 | * @param {number} [max] Maximum boundary for the random value, excluded
|
32 | * @return {number | Array | Matrix} A random integer value
|
33 | */
|
34 | // TODO: rework randomInt to a typed-function
|
35 | const randomInt = distribution('uniform').randomInt
|
36 |
|
37 | randomInt.toTex = undefined // use default template
|
38 |
|
39 | return randomInt
|
40 | }
|
41 |
|
42 | exports.name = 'randomInt'
|
43 | exports.factory = factory
|