SQLite Random

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

Syntax

random()Code language: SQL (Structured Query Language) (sql)

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();Code language: SQL (Structured Query Language) (sql)
random()
-----------
8713427140561224584

In case the number of rows in a table is small, you can use the random() function to get a number of random rows. For example, to get 5 random albums in the albums table, you use the following statement:

SELECT title FROM albums
ORDER BY random() 
LIMIT 5;Code language: SQL (Structured Query Language) (sql)
Title
-------------------------
Deep Purple In Rock
Live After Death
A Matter of Life and Death
Na Pista
The Best Of 1980-1990Code language: Shell Session (shell)
Was this tutorial helpful ?