Skip to content

randomInt - Generate a pseudorandom integer

randomInt will create a pseudorandom number between 0 and n exclusively.

Note

randomInt is not a cryptographically secure source of randomness.

Syntax

Like many functions in DataPrime, randomInt supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

randomInt(upperBound: number): number
upperBound: number.randomInt(): number

Arguments

NameTypeRequiredDescription
upperBoundnumbertrueThe highest value the random number can be, exclusively.

Example - Basic usage

To create a random number from 0 to 99 and add it as a field named random_num to a document, one can simple combine randomInt with the create command:

create random_num from randomInt(100)
create random_num from 100.randomInt()