Skip to content
On this page

Random

Generates random values of different kinds.

alpha

Generating a string consisting of letters in the English alphabet.

Available since v5.0.0

Parameters

NameTypeDefaultDescription
optionsnumber | { ... }{}

Either the number of characters or an options instance.

options.bannedChars?readonly LiteralUnion<AlphaChar, string>[] | string[]

An array with characters to exclude.

options.casing?Casing'lower'

The casing of the characters.

options.count?number1

The number of characters to generate.

options.upcase?boolean

Missing

Returns: string

ts
faker.random.alpha(options: number | {
  bannedChars: readonly LiteralUnion<AlphaChar, string>[] | string,
  casing: Casing,
  count: number,
  upcase: boolean
} = {}): string
faker.random.alpha() // => "o"
faker.random.alpha() // 'b'
faker.random.alpha(10) // 'qccrabobaf'
faker.random.alpha({ count: 5, casing: 'upper', bannedChars: ['A'] }) // 'DTCIC'

alphaNumeric

Generating a string consisting of alpha characters and digits.

Available since v3.1.0

Parameters

NameTypeDefaultDescription
countnumber1

The number of characters and digits to generate.

options{ ... }{}

The options to use.

options.bannedChars?readonly LiteralUnion<AlphaNumericChar, string>[] | string[]

An array of characters and digits which should be banned in the generated string.

options.casing?Casing'lower'

The casing of the characters.

Returns: string

ts
faker.random.alphaNumeric(count: number = 1, options: {
  bannedChars: readonly LiteralUnion<AlphaNumericChar, string>[] | string,
  casing: Casing
} = {}): string
faker.random.alphaNumeric() // => "j"
faker.random.alphaNumeric() // '2'
faker.random.alphaNumeric(5) // '3e5v7'
faker.random.alphaNumeric(5, { bannedChars: ["a"] }) // 'xszlm'

locale

Returns a random locale, that is available in this faker instance. You can use the returned locale with faker.setLocale(result).

Available since v3.1.0

Returns: string

ts
faker.random.locale(): string
faker.random.locale() // => "hu"
faker.random.locale() // 'el'

numeric

Generates a given length string of digits.

Available since v6.3.0

Parameters

NameTypeDefaultDescription
lengthnumber1

The number of digits to generate.

options{ ... }{}

The options to use.

options.allowLeadingZeros?booleanfalse

If true, leading zeros will be allowed.

options.bannedDigits?readonly LiteralUnion<NumericChar, string>[] | string[]

An array of digits which should be banned in the generated string.

Returns: string

ts
faker.random.numeric(length: number = 1, options: {
  allowLeadingZeros: boolean,
  bannedDigits: readonly LiteralUnion<NumericChar, string>[] | string
} = {}): string
faker.random.numeric() // => "5"
faker.random.numeric() // '2'
faker.random.numeric(5) // '31507'
faker.random.numeric(42) // '56434563150765416546479875435481513188548'
faker.random.numeric(42, { allowLeadingZeros: true }) // '00564846278453876543517840713421451546115'
faker.random.numeric(6, { bannedDigits: ['0'] }) // '943228'

word

Returns random word.

Available since v3.1.0

Returns: string

ts
faker.random.word(): string
faker.random.word() // => "quantify"
faker.random.word() // 'Seamless'

words

Returns string with set of random words.

Available since v3.1.0

Parameters

NameTypeDefaultDescription
count?number

Number of words. Defaults to a random value between 1 and 3.

Returns: string

ts
faker.random.words(count?: number): string
faker.random.words() // => "Latin Minivan"
faker.random.words() // 'neural'
faker.random.words(5) // 'copy Handcrafted bus client-server Point'

Released under the MIT License.