SQLite Tutorial SQLite Advanced SQLite Database SQLite References

SQLite RANDOMBLOB() Function



The SQLite RANDOMBLOB() function returns an N-byte blob containing pseudo-random bytes. If N is less than 1 then a 1-byte random blob is returned.

Note: It can be used by applications to generate globally unique identifiers using this function together with HEX() and/or LOWER(). For example - HEX(RANDOMBLOB(16)), LOWER(HEX(RANDOMBLOB(16)))

Syntax

RANDOMBLOB(N)

Parameters

N Required. Specify the number of bytes.

Return Value

Returns an N-byte blob containing pseudo-random bytes.

Example: RANDOMBLOB() example

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

SELECT HEX(RANDOMBLOB(16));
Result: '1D9CF5BAFDCC16822272A376AE2A5212'

SELECT LOWER(HEX(RANDOMBLOB(16)));
Result: 'afbc9e8f110aa8d56a00700773844f1e'

SELECT HEX(RANDOMBLOB(32));
Result: 'AAFD9969B596E4AA0A10B5F7D98ECA6AB5A87517195F346C4B2D48AFA6EDFF85'

SELECT LOWER(HEX(RANDOMBLOB(32)));
Result: 'e3dbe33a8b8d4d47f0a45f3df69d243520cfd5ceacab42007364e7ee1072a535'

❮ SQLite Functions