mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
54 lines
2.0 KiB
Markdown
54 lines
2.0 KiB
Markdown
---
|
|
layout: default
|
|
---
|
|
|
|
<h1 id="function-randomint">Function randomInt <a href="#function-randomint" title="Permalink">#</a></h1>
|
|
|
|
Return a random integer number between `min` and `max` using a uniform distribution.
|
|
|
|
|
|
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
math.randomInt() // generate a random integer between 0 and 1
|
|
math.randomInt(max) // generate a random integer between 0 and max
|
|
math.randomInt(min, max) // generate a random integer between min and max
|
|
math.randomInt(size) // generate a matrix with random integer between 0 and 1
|
|
math.randomInt(size, max) // generate a matrix with random integer between 0 and max
|
|
math.randomInt(size, min, max) // generate a matrix with random integer between min and max
|
|
```
|
|
|
|
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
|
|
|
|
Parameter | Type | Description
|
|
--------- | ---- | -----------
|
|
`size` | Number | If provided, an array with `size` number of random values is returned
|
|
`min` | Number | Minimum boundary for the random value
|
|
`max` | Number | Maximum boundary for the random value
|
|
|
|
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
|
|
|
|
Type | Description
|
|
---- | -----------
|
|
Number | Array | Matrix | A random integer value
|
|
|
|
|
|
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
|
|
|
|
```js
|
|
math.randomInt(); // returns a random integer between 0 and 1
|
|
math.randomInt(100); // returns a random integer between 0 and 100
|
|
math.randomInt(30, 40); // returns a random integer between 30 and 40
|
|
math.randomInt([2, 3]); // returns a 2x3 matrix with random integers between 0 and 1
|
|
```
|
|
|
|
|
|
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
|
|
|
|
[randomInt](randomInt.html),
|
|
[pickRandom](pickRandom.html),
|
|
[distribution](distribution.html)
|
|
|
|
|
|
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
|