Based on the answer of @jankkhvej
I will do a modification to the code to control generating PRNG using a predefined seed (integer-32 bit number) and document the code.
Actually the seed in PHP is defined using the function mt_srand($seed)
//define seed (modify it as needed), so you can get the same series every time you run the code.
$seed=123456789;
//mt_srand — Seeds the Mersenne Twister Random Number Generator
mt_srand($seed);
//compute hash md5 for mt_rand()
$md5 = md5(mt_rand());
//use md5 to get a decimal number by replacing the hex-decimal chars abcef by numeric values, then prefix the result with "0."
$prng = ('0.' . str_replace(['0', 'a', 'b', 'c', 'd', 'e', 'f'], ['7', '3', '1', '5', '9', '8', '4'], $md5 )) * 1;
//sqlite is using rowid, a unique number for row. If you defined a primary key, it can be rowid.
//multiply rowid by $prng , and extract only the fraction part using substr function
//e.g 1.0519815151568 will be 0519815151568
$query = "SELECT id, name FROM table ORDER BY (substr(rowid * $prng , length(rowid) + 2))";
Try onlin demo
output
seed= 1234567890
mt_rand= 1328851649
MD5 hash= 1abfd768d39fc907c278ec2cb8ae809b
prng= 0.1314976893946
SQLite version 3.7.17
Selecting 3 random rows of 10, with PRNG: 0.1314976893946
Id name rowid*prng random
8 p_8 1.0519815151568 0519815151568
1 p_1 0.1314976893946 1314976893946
10 p_10 1.314976893946 14976893946
I provided an alternative solution to generate PNRG , you can find here