Core functions
random
random(): numberThis is light-fakery's internal random number generator (PRNG), although it's exposed in case you want to generate raw random numbers.
It returns numbers between 0 and 1, and by default initializes with a seed based on the current time. To create a deterministic generator, call the setSeed function; after that point all light-fakery functions will use the custom seed.
import { random } from 'light-fakery'
random()
// => 0.20554963243193924randomBoolean
randomBoolean(): booleanA convenience method that returns either true or false with equal probability.
import { randomBoolean } from 'light-fakery'
randomBoolean()
// => truerandomInteger
randomInteger(options: { min: number, max: number }): numberReturns a random integer between min and max.
Both min and max are required and the result is inclusive of the endpoints.
import { randomInteger } from 'light-fakery'
randomInteger({ min: 0, max: 100 })
// => 63randomFromArray
randomFromArray<T>(array: T[]): TReturns a random element from an array. The array can't be empty.
import { randomFromArray } from 'light-fakery'
randomFromArray([1, 2, 3])
// => 3randomDate
randomDate(options: { from: Date, to: Date }): DateReturns a random JavaScript Date between the provided values. Both from and to are required and the result is inclusive of the endpoints.
import { randomDate } from 'light-fakery'
randomDate({
from: new Date('January 1, 2023'),
to: new Date('December 31, 2023'),
})
// => 2023-08-17T12:07:04.602Z