SQLite Tutorial SQLite Advanced SQLite Database SQLite References

SQLite RANDOM() Function



The SQLite RANDOM() function returns a pseudo-random integer between -9223372036854775808 and +9223372036854775807.

Syntax

RANDOM()

Parameters

No parameter is required.

Return Value

Returns a random number between -9223372036854775808 and +9223372036854775807.

Example:

The example below shows the usage of RANDOM() function.

SELECT RANDOM();
Result: -2991495863549541805

SELECT RANDOM();
Result: 8268347114975837434

SELECT RANDOM();
Result: 6869755847039874407

Random Integer in a given Range

The SQLite RANDOM() function can be used to create a random integer between a given range. For example - to create a random number in a range [a, b], the following formula can be used:

SELECT ABS(RANDOM())%(b-a) + a;

Example:

In the example below, the RANDOM function is used to create a random number between a range [100, 200].

SELECT ABS(RANDOM())%(200-100) + 100;
Result: 114

SELECT ABS(RANDOM())%(200-100) + 100;
Result: 177

SELECT ABS(RANDOM())%(200-100) + 100;
Result: 130

❮ SQLite Functions