Number
Module to generate numbers of any kind.
Overview
For simple integers, use {{$number.int}}
. For decimal/floating-point numbers, use {{$number.float}}
.
For numbers not in base-10, you can use {{$number.hex}}, {{$number.octal}}
and {{$number.binary}}
.
Related modules
For numeric strings of a given length, use {{$string.numeric}}
.
For credit card numbers, use {{$finance.creditCardNumber}}
.
bigInt
Returns a BigInt number. The bounds are inclusive.
Parameters
Name | Type | Default | Description |
---|---|---|---|
max | string | number | bigint | | min + 999999999999999n | Upper bound for generated bigint. |
min | string | number | bigint | | 0n | Lower bound for generated bigint. |
Returns: bigint
Examples
{{$number.bigInt}} // '658577825017810'
{{$number.bigInt(min='1000000')}} // '393309651182825'
{{$number.bigInt(max='100')}} // ’24‘
{{$number.bigInt(min='10',max='100')}} // ‘34’
binary
Returns a binary number. The bounds are inclusive.
Parameters
Name | Type | Default | Description |
---|---|---|---|
max | string | number | bigint | | 1 | Upper bound for generated number. |
min | string | number | bigint | | 0 | Lower bound for generated number. |
Returns: string
Examples
{{$number.binary}} // '1'
{{$number.binary(min=0,max=65535)}} // ‘100101100011000’
float
Returns a single random floating-point number, by default between 0.0
and 1.0
. To change the range, pass a min
and max
value. To limit the number of decimal places, pass a multipleOf
or fractionDigits
parameter.
Parameters
Name | Type | Default | Description |
---|---|---|---|
fractionDigits | number | The maximum number of digits to appear after the decimal point, for example 2 will round to 2 decimal points. Only one of multipleOf or fractionDigits should be passed | |
max | number | 1.0 | Upper bound for generated number, exclusive, unless multipleOf or fractionDigits are passed. |
max | number | 0.0 | Lower bound for generated number, inclusive. |
multipleOf | number | The generated number will be a multiple of this parameter. Only one of multipleOf or fractionDigits should be passed. |
Returns: number
Examples
{{$number.float}} // '0.6293353106763337'
{{$number.float(max=100)}} // ‘61.583601816789745’
{{$number.float(min=20,max=100)}} // ‘88.93489807538822’
{{$number.float(min=20,max=100,multipleOf=0.25)}} // ’25‘
{{$number.float(min=20,max=100,fractionDigits=3)}} // ’83.294‘
hex
Returns a lowercase hexadecimal number. The bounds are inclusive.
Parameters
Name | Type | Default | Description |
---|---|---|---|
max | number | 15 | Upper bound for generated number |
max | number | 0 | Lower bound for generated number |
Returns: string
Examples
{{$number.hex}} // 'e'
{{$number.hex(min=0,max=65535)}} // ‘90ff’
int
Returns a single random integer between zero and the given max value or the given range. The bounds are inclusive.
Parameters
Name | Type | Default | Description |
---|---|---|---|
max | number | Number.MAX_SAFE_INTEGER | Upper bound for generated number |
max | number | 0 | Lower bound for generated number |
multipleOf | number | 1 | Generated number will be a multiple of the given integer. |
Returns: number
Examples
{{$number.int}} // '3014636528100856'
{{$number.int(min=1000000)}} // ‘613071964516055’
{{$number.int(max=100)}} // '46'
{{$number.int(min=10,max=100)}} // '37'
{{$number.int(min=10,max=100,multipleOf=10)}} // '50'
octal
Returns an octal number. The bounds are inclusive.
Parameters
Name | Type | Default | Description |
---|---|---|---|
max | number | 7 | Upper bound for generated number |
max | number | 0 | Lower bound for generated number |
Returns: string
Examples
{{$number.octal}} // '4'
{{$number.octal(min=0,max=65535)}} // ‘144567’