random_number
Generate a random number, a list of them, or a generator with optional configuration
Usage
import randomNumber from "https://deno.land/x/random_number/mod.ts";
randomNumber(); //=> 0.419534816957152
A more complete example using all API:
import {
randomNumber,
randomNumberGenerator,
randomNumberList,
} from "https://deno.land/x/random_number/mod.ts";
const randomInteger = randomNumber({ integer: true, max: 5 });
console.log(`Random integer: ${randomInteger}`);
const randomDecimal = randomNumber();
console.log(`Random decimal: ${randomDecimal}`);
const randomNumbers = randomNumberList(randomInteger);
console.log(`List Random numbers: ${randomNumbers.join(", ")}.`);
const rdGenerator = randomNumberGenerator({ integer: true, max: 50 });
for (let index = 1; index < 5; index++) {
console.log(`Time <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi>i</mi><mi>n</mi><mi>d</mi><mi>e</mi><mi>x</mi></mrow><mo>:</mo></mrow><annotation encoding="application/x-tex">{index}: </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord"><span class="mord mathnormal">in</span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal">x</span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">:</span></span></span></span>{rdGenerator()}`);
}
API
randomNumber(options)
Receive options
This is exported as default and as a named export for flexibility.
randomNumberGenerator(options)
Receive options
randomNumberList(length, options)
length
Type: number
The length of the wanted array of random numbers.
Options
A TypeScript type.
min
Type: number
|| undefined
The minimum value
max
The maximum value
Type: number
|| undefined
integer
Type: boolean
|| undefined
Makes the result an integer instead of a decimal
License
This project is licensed under the MIT License.