i'm getting an issue relating to the use of the random() function in a 
SQL query.

i run 2 PHP scripts very quickly (less than 1 second apart).

they use an SQL query like    SELECT * FROM table ORDER BY random() LIMIT 5;

because the 2 scripts run so close together (in time)  i get the same 
values as a result.
this is somewhat difficult to isolate to prove its any one piece of 
technologies issue.

i know at this point you'd like to dismiss it as PHP, PDO, the HTTPd, 
the browser, caches, anything but sqlite... the probability you are 
right is very high, agreed,  however...

after some investigation into how sqlite generates its first random 
numbers..  (the first after seeding),  means the seed is effectively 
controlling the probability of getting a random number.

the platform i'm using is Windows,  and the seeding occurs in this function:
static int winRandomness();      (somewhere in the windows specific src 
section of sqlite)

in that function, is there any reason why the less volatile source of 
randomness is appended to the buffer first?
wouldn't it be better to have the most volatile values first..
the QueryPerformanceCounter()  is a very high frequency counter, it 
first would give this seed string more volatile bits at its beginning.


I'm not sure if this will ultimately solve the problem from the 20th 
abstraction of my SQL query using random()   but its a step in the right 
direction!


when i run the same 2 scripts more than a second apart, i get random 
numbers.
it has something to do with a clock value.  i know its a big leap thru 
20 abstraction layers from SQL random()  to a  win32 call deep in sqlite 
src code, but thats one of the places the clock count is used.

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to