Skip to content

Random

Deprecated

This module is deprecated and will be removed in a future version.

Use the modules specific to the type of data you want to generate instead.

Generates random values of different kinds.

alpha

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.string.alpha() instead.

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 Array<AlphaChar | string> | string[]

An array with characters to exclude.

options.casing?Casing'mixed'

The casing of the characters.

options.count?number1

The number of characters to generate.

Returns: string

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

alphaNumeric

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.string.alphanumeric() instead.

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 Array<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 Array<AlphaNumericChar | string> | string,
  casing: Casing
} = {}): string
faker.random.alphaNumeric() // '2'
faker.random.alphaNumeric(5) // '3e5v7'
faker.random.alphaNumeric(5, { bannedChars: ["a"] }) // 'xszlm'

numeric

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.string.numeric() instead.

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?booleantrue

Whether leading zeros are allowed or not.

options.bannedDigits?readonly Array<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 Array<NumericChar | string> | string
} = {}): string
faker.random.numeric() // '2'
faker.random.numeric(5) // '31507'
faker.random.numeric(42) // '00434563150765416546479875435481513188548'
faker.random.numeric(42, { allowLeadingZeros: true }) // '00564846278453876543517840713421451546115'
faker.random.numeric(6, { bannedDigits: ['0'] }) // '943228'

word

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.lorem.word() or faker.word.sample() instead.

Returns a random word.

Available since v3.1.0

Returns: string

ts
faker.random.word(): string
faker.random.word() // 'Seamless'

words

Deprecated

This method is deprecated and will be removed in a future version.

Use faker.lorem.words() or faker.word.words() instead.

Returns a string with a given number of random words.

Available since v3.1.0

Parameters

NameTypeDefaultDescription
countnumber | { ... }{ min: 1, max: 3 }

The number or range of words. Defaults to a random value between 1 and 3.

count.maxnumber

The maximum number of words.

count.minnumber

The minimum number of words.

Returns: string

ts
faker.random.words(count: number | {
  max: number,
  min: number
} = { min: 1, max: 3 }): string
faker.random.words() // 'neural'
faker.random.words(5) // 'copy Handcrafted bus client-server Point'
faker.random.words({ min: 3, max: 5 }) // 'cool sticky Borders'

Released under the MIT License.