Skip to content

randomInt

Description

Returns a pseudorandom integer between 0 (inclusive) and an upper bound (exclusive).

Note

Not cryptographically secure.

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 exclusive upper limit for the random number

Example

Use case: Generate a random integer within a range

Create a pseudorandom integer between 0 and 99 and attach it to each document.

{
    "event": "login_attempt"
}
create random_num from randomInt(100)
create random_num from 100.randomInt()

Output

{
    "event": "login_attempt",
    "random_num": 57
}