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
Name | Type | Default | Description |
---|---|---|---|
options | number | { ... } | {} | 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? | number | 1 | The number of characters to generate. |
Returns: string
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'
Source
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
Name | Type | Default | Description |
---|---|---|---|
count | number | 1 | 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
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'
Source
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
Name | Type | Default | Description |
---|---|---|---|
length | number | 1 | The number of digits to generate. |
options | { ... } | {} | The options to use. |
options.allowLeadingZeros? | boolean | true | 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
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'
Source
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
faker.random.word(): string
faker.random.word() // 'Seamless'
See Also
Source
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
Name | Type | Default | Description |
---|---|---|---|
count | number | { ... } | { min: 1, max: 3 } | The number or range of words. Defaults to a random value between |
count.max | number | The maximum number of words. | |
count.min | number | The minimum number of words. |
Returns: string
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'