#Basics
#bool
Return a random boolean value (true
or false
).
The default likelihood of success (returning true
) is 50%. Can optionally specify the likelihood in percent:
In this case only a 30% likelihood of true
, and a 70% likelihood of false
.
#character
Return a random character.
By default it will return a string with random character from the following pool.
Optionally specify a pool and the character will be generated with characters only from that pool.
Optionally specify alpha for an alphabetic character.
Optionally specify numeric for a numeric character.
Default includes both upper and lower case. It's possible to specify one or the other.
Note, wanted to call this key just case
but unfortunately that's a reserved word in JavaScript for use in a switch statement
Optionally return only symbols
#falsy
Return a random falsy value (false
, null
, undefined
, 0
, NaN
, ''
).
The default pool can be changed to better meet the needs:
#floating
I wanted to use float or double as the method name but both are JS reserved words even though they aren't really used...
Return a random floating point number.
By default it will return a fixed number of at most 4 digits after the decimal.
Note: at most 4 digits. This because, unless we returned trailing zeroes (which aren't allowed on the JavaScript float) we can't guarantee 4 digits after the decimal. So if random chance comes back with 82383854.2000
then 82383854.2
is what will be returned.
To retrieve a set number of fixed digits after the decimal, provide it as an option.
As with other number functions, can include a min and/or max.
Or combine them.
#integer
9007199254740991 is 2^53 - 1 and is the largest number value in JavaScript
Return a random integer.
range: -9007199254740991 to 9007199254740991
See: Largest number in JavaScript
Can optionally provide min and max.
These min and max are inclusive, so they are included in the range. This means
would return either -2, -1, 0, 1, or 2.
#letter
Return a random letter.
By default it will return a random lowercase letter.
Note, wanted to call this option just case instead of casing but unfortunately that's a reserved word in JavaScript for use in a switch statement
It's possible to specify upper case
#natural
Return a natural number.
range: 0 to 9007199254740991
Can optionally provide min and max.
Can optionally provide numbers you wish to exclude.
These are inclusive, so they are included in the range. This means {{natural({min: 1, max: 3})}};
would return either 1, 2, or 3 or:
#prime
Return a prime number.
default range: 0 to 10000
Can optionally provide min and max.
These are inclusive, so they are included in the range. This means {{prime({min: 2, max: 5})}};
would return either 2, 3, or 5 or:
#string
Return a random string.
By default it will return a string with random length of 5-20 characters and will contain any of the following characters.
Can optionally specify a length and the string will be exactly that length.
Can optionally specify a min and the string will have a minimum length
Can optionally specify a max and the string will have a maximum length
Can optionally specify a pool and the string will be generated with characters only from that pool.
Of course these options can also be combined, using length or min and max.
All the options for {{character()}} are supported:
#template
Return a random string matching the given template.
The template consists of any number of "character replacement" and "character literal" sequences. A "character replacement" sequence starts with a left brace, has any number of special replacement characters, and ends with a right brace. A character literal can be any character except a brace or a backslash. A literal brace or backslash character can be included in the output by escaping with a backslash.
The following replacement characters can be used in a replacement sequence:
- "#": a random digit
- "a": a random lower case letter
- "A": a random upper case letter