SQLite Random() Function

Savigo
You organize your data. Now organize your savings.
Set savings goals, track your progress, and stay on course.
Get Savigo for iPhone 

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

Syntax #

random()

Arguments #

The random() function takes no argument.

Return Type #

Integer

Examples #

The following statement uses the random() function to return a random integer.

SELECT random();
random()
-------------------
8713427140561224584

If the number of rows in a table is small, you can use the random() function to get a number of random rows.

For example, the following example uses the random() function to retrieve 5 random albums from the albums table:

SELECT title 
FROM albums
ORDER BY random() 
LIMIT 5;

Output:

Title
-------------------------
Deep Purple In Rock
Live After Death
A Matter of Life and Death
Na Pista
The Best Of 1980-1990

Was this tutorial helpful?