Seeding SQLite RANDOM()
NickName:Alix Axel Ask DateTime:2010-01-31T20:03:37

Seeding SQLite RANDOM()

Does SQLite support seeding the RANDOM() function the same way MySQL does with RAND()?

$query = "SELECT * FROM table ORDER BY RAND(" . date('Ymd') . ") LIMIT 1;";

From the MySQL Manual about RAND(N):

If a constant integer argument N is specified, it is used as the seed value, which produces a repeatable sequence of column values. In the following example, note that the sequences of values produced by RAND(3) is the same both places where it occurs.

If not, is there any way to archive the same effect using only one query?

Copyright Notice:Content Author:「Alix Axel」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/2171578/seeding-sqlite-random

Answers
Thomas 2010-01-31T12:14:04

Have a look at the sqlite3_randomness() function:\n\n\n SQLite contains a high-quality pseudo-random number generator (PRNG) used to select random ROWIDs when inserting new records into a table that already uses the largest possible ROWID. The PRNG is also used for the build-in random() and randomblob() SQL functions.\n \n ...\n \n The first time this routine is invoked (either internally or by the application) the PRNG is seeded using randomness obtained from the xRandomness method of the default sqlite3_vfs object. On all subsequent invocations, the pseudo-randomness is generated internally and without recourse to the sqlite3_vfs xRandomness method. \n\n\nLooking at the source of this xRandomness method, you can see that it reads from /dev/urandom on Unix. On Windows, it just returns the return values of some time functions. So it seems that your only option is to start hacking on the SQLite source code.",


More about “Seeding SQLite RANDOM()” related questions

Seeding SQLite RANDOM()

Does SQLite support seeding the RANDOM() function the same way MySQL does with RAND()? $query = "SELECT * FROM table ORDER BY RAND(" . date('Ymd') . ") LIMIT 1;"; From the MySQL Manual about RAND...

Show Detail

ORDER BY random() with seed in SQLITE

I would like to implement paging for a random set Select * from Animals ORDER BY random(SEED) LIMIT 100 OFFSET 50 I tried to set int to some integer and to some fracture. Doesn't work. How do I ...

Show Detail

artisan migration and seeding on sqlite in memory, always empty?

I'm trying to setup migration and seeding for a Laravel 5.4 application. Migration and seeding are working for mysql db. However when I try to run it on a sqlite in memory db, it seems to me that t...

Show Detail

PHP random_int seeding

As of PHP7, a new function was introduced for PRNG: random_int (http://php.net/manual/en/function.random-int.php) There is no information in the PHP manual related to the seeding of this function,...

Show Detail

Random seeding in open AI gym

I have a question about seeding in open AI gym and utilizing it in custom environments. Let's take the lunar lander environment for example, the default seeding function is: def seed(self, seed=No...

Show Detail

seeding secure random in java

I wish to generate random integers using SecureRandom in java. private SecureRandom myRandom = new SecureRandom(); private int myInt = 10; int myResults; myResults = myRandom.nextInt(myInt); I

Show Detail

Random seeding in Game of Life cannot working well

I'm developing game of life for my assignment. I try to use random number for seeding but the next generation is not working. How can I use the random seeding to check the next generation. When I u...

Show Detail

Random number generator generating the same number even after seeding

Here's my code: #include <iostream> #include <string> #include <random> #include <ctime> using namespace std; int RandomIntGen(int lowerLimit, int upperLim

Show Detail

seeding and random number generating

I am trying to understand the random-generating-function in c. For what I read the random number returned by the function is dependent on its initial value, called a seed that remains the same fo...

Show Detail

Why is seeding the random generator not stable between versions of Python?

I am trying to reproduce a random sequence from python's random.random() on a different system with a different python3 version installed. This should be easy as the documentation says: Most of...

Show Detail