SQLite | SQLite Functions | Generate Random Numbers for BLOB Values (randomblob Function)

The randomblob function can generate random numbers for BLOB type values. This section explains how to use the randomblob function.

How to Use the randomblob Function

The randomblob function is used to generate random values of the BLOB type. The format is as follows.

randomblob(bytes)

It generates a random BLOB value with the number of bytes specified in the argument. Specify a positive value for the byte count.

Now, use the randomblob function in practice to generate random values. The generated values are output in hexadecimal by using the hex function. (For the hex function, see Convert a BLOB Type Value to Hexadecimal (hex Function).)

select hex(randomblob(2)), hex(randomblob(3));
sqlite> select hex(randomblob(2)), hex(randomblob(3));
hex(randomblob(2))  hex(randomblob(3))
------------------  ------------------
FF28                FCBE5D            
sqlite> select hex(randomblob(2)), hex(randomblob(3));
hex(randomblob(2))  hex(randomblob(3))
------------------  ------------------
9870                77795A            
sqlite> select hex(randomblob(2)), hex(randomblob(3));
hex(randomblob(2))  hex(randomblob(3))
------------------  ------------------
BAE1                A61970            
sqlite> 

Each time the SELECT statement was executed, 2-byte and 3-byte BLOB type values were displayed.