Re: [sqlite] Equal distribution from random rows

2007-05-31 Thread John Elrick
Alex Teslik wrote: On Wed, 30 May 2007 15:18:18 -0400, John Elrick wrote After running a simple test, I confirmed a suspicion. VACUUM doesn't reorder the ROWIDs, so you still have breaks. My tests show otherwise: SNIP did I do something incorrectly? Not incorrectly, just

Re: [sqlite] Equal distribution from random rows

2007-05-30 Thread Jeffrey Rennie
Here's a naive solution, which requires some programming language around the SQL: BEGIN TRANSACTION n = (SELECT count(*) from table) i = RandBetween(0, n) row = (SELECT * from table LIMIT 1 OFFSET i) END TRANSACTION I'm posting this because I suspect that this naive solution isn't correct, but I

Re: [sqlite] Equal distribution from random rows

2007-05-30 Thread Alex Teslik
On Wed, 30 May 2007 15:18:18 -0400, John Elrick wrote > After running a simple test, I confirmed a suspicion. VACUUM > doesn't reorder the ROWIDs, so you still have breaks. My tests show otherwise: [alex]# cat 01_vacuum_table_test.sql CREATE TABLE foo ( string varchar(1) not null ); INSERT I

Re: [sqlite] Equal distribution from random rows

2007-05-30 Thread Jiri Hajek
Is there a way I can modify my query to attain a much more equal distribution? It doesn't have to be perfect, but right now it is too noticiably weighted. What about this: SELECT * FROM Table LIMIT 1 OFFSET round((CAST(random(*) as float)/(9223372036854775807)+1)/2*(SELECT COUNT(*) FROM Tabl

Re: [sqlite] Equal distribution from random rows

2007-05-30 Thread John Elrick
Alex Teslik wrote: Hello, I'm working on a project that requires random images to be chosen from a live database for a dynamic homepage. I found this link from Dr. Hipp that details a very fast approach to selecting random rows: http://www.mail-archive.com/sqlite-users@sqlite.org/msg14652.ht

[sqlite] Equal distribution from random rows

2007-05-30 Thread Alex Teslik
Hello, I'm working on a project that requires random images to be chosen from a live database for a dynamic homepage. I found this link from Dr. Hipp that details a very fast approach to selecting random rows: http://www.mail-archive.com/sqlite-users@sqlite.org/msg14652.html Unfortunately,