# Basics

# bool

// usages
{{bool()}}
{{bool({ likelihood: 30 })}}

Return a random boolean value (true or false).

{{bool()}};
=> true

The default likelihood of success (returning true) is 50%. Can optionally specify the likelihood in percent:

{{bool({likelihood: 30})}};
=> false

In this case only a 30% likelihood of true, and a 70% likelihood of false.


# character

// usages
{{character()}}
{{character({ pool: 'abcde' })}}
{{character({ alpha: true })}}
{{character({ numeric: true })}}
{{character({ casing: 'lower' })}}
{{character({ symbols: true })}}

Return a random character.

{{character()}};
=> 'v'

By default it will return a string with random character from the following pool.

'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()'

Optionally specify a pool and the character will be generated with characters only from that pool.

{{character({ pool: 'abcde' })}};
=> 'c'

Optionally specify alpha for an alphabetic character.

{{character({ alpha: true })}};
=> 'N'

Optionally specify numeric for a numeric character.

{{character({ numeric: true })}};
=> '8'

Default includes both upper and lower case. It's possible to specify one or the other.

{{character({ casing: 'lower' })}};
=> 'j'

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

{{character({ symbols: true })}};
=> '%'

# falsy

// usages
{{falsy()}}
{{falsy({ pool: [ NaN, undefined ] })}}

Return a random falsy value (false, null, undefined, 0, NaN, '').

{{falsy()}};
=> false

The default pool can be changed to better meet the needs:

{{falsy({ pool: [ NaN, undefined ] })}};
=> NaN

# floating

// usages
{{floating()}}
{{floating({ fixed: 7 })}}
{{floating({ min: 0, max: 100 })}}

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.

{{floating()}};
=> -211920142886.5024

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.

{{floating({ fixed: 7 })}};
=> -749512327.7447168

As with other number functions, can include a min and/or max.

{{floating({ min: 0, max: 100 })}};
=> 31.9021

Or combine them.

{{floating({ min: 0, max: 100, fixed: 8 })}};
=> 45.92367599

# integer

// usage
{{integer()}}
{{integer({ min: -20, max: 20 })}}

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

{{integer()}};
=> -1293235

Can optionally provide min and max.

{{integer({ min: -20, max: 20 })}}
=> -7

These min and max are inclusive, so they are included in the range. This means

{{integer({ min: -2, max: 2 })}}

would return either -2, -1, 0, 1, or 2.

// Specific case
-2 <= random number <= 2

// General case
min <= random number <= max

# letter

// usage
{{letter()}}
{{letter({ casing: 'lower' })}}

Return a random letter.

{{letter()}};
=> 'p'

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

{{letter({casing: 'upper'})}};
=> 'A'

# natural

// usage
{{natural()}}
{{natural({ min: 1, max: 20 })}}

Return a natural number.

range: 0 to 9007199254740991

  {{natural()}};
  => 125019392395

Can optionally provide min and max.

{{natural({min: 1, max: 20})}};
=> 14

Can optionally provide numbers you wish to exclude.

{{natural({min: 1, max: 5, exclude: [1, 3]})}};
=> 2

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:

// Specific case
1 <= random number <= 3

// General case
min <= random number <= max

Natural Number on Wikipedia


# prime

// usage
{{prime()}}
{{prime({ min: 1, max: 20 })}}

Return a prime number.

default range: 0 to 10000

  {{prime()}};
  => 929

Can optionally provide min and max.

{{prime({min: 1, max: 20})}};
=> 13

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:

// Specific case
2 <= random number <= 5

// General case
min <= random number <= max

Prime Number on Wikipedia


# string

// usage
{{string()}}
{{string({ length: 5 })}}
{{string({ min: 5 })}}
{{string({ max: 50 })}}
{{string({ min: 5, max: 20 })}}
{{string({ pool: 'abcde' })}}
{{string({ alpha: true })}}
{{string({ numeric: true })}}
{{string({ casing: 'lower' })}}
{{string({ symbols: true })}}

Return a random string.

  {{string()}};
  => 'Z&Q78&fqkPq'

By default it will return a string with random length of 5-20 characters and will contain any of the following characters.

  'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()[]'

Can optionally specify a length and the string will be exactly that length.

  {{string({ length: 5 })}};
  => 'YN%fG'

Can optionally specify a min and the string will have a minimum length

  {{string({ min: 5 })}};
  => '6(Ow1wF)qjUm%W)B2[Q]'

Can optionally specify a max and the string will have a maximum length

  {{string({ max: 20 })}};
  => 'k7fubkfMS@gs#E'

Can optionally specify a pool and the string will be generated with characters only from that pool.

  {{string({ pool: 'abcde' })}};
  => 'cccdeeabedebb'

Of course these options can also be combined, using length or min and max.

  {{string({ length: 5, pool: 'abcde' })}};
  => 'cbbdc'
  {{string({ min: 5, max: 20, pool: 'abcde' })}};
  => 'ebddceaaceeda'

All the options for {{character()}} are supported:

  {{string({ length: 8, casing: 'upper', alpha: true, numeric: true })}};
  => '3THK7GB1'

# template

Return a random string matching the given template.

// usage
{{template('{AA####}')}}
=> 'ZQ7803'
{{template('{Aa}-{##}')}}
=> 'Vr-78'
{{template('{####}:{####}:{####}')}}
=> '1628:5987:7803'

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