"Dave Dembinski" <thealmightydaev / hotmail.com> schrieb im Newsbeitrag news:c67f8ee3.0306251214.295d28a8 / posting.google.com... > Using MySQL Ruby for a website, and trying to use the built-in RAND() > function to get a list of 10 links from a database. Now, on the > server in the command-line, it works just fine: > > %mysql> select id from links order by rand() * 10 limit 10; > %+----+ > %| id | > %+----+ > %| 37 | > %| 26 | > %| 24 | > %| 46 | > %| 53 | > %| 43 | > %| 38 | > %| 23 | > %| 21 | > %| 58 | > %+----+ > %10 rows in set (0.00 sec) > > Great! But when I try and do this using Ruby and MySQL Ruby. . . > > %links = my.query('select id from links order by rand() * 10 limit > 10;') I don't know mysql but I'm sure ruby does not change the query in any way that would affect this. Your probe is very small to be statistically significant. I'd do an automated test, that does statistical evaluation to verify the distribution. A reason for different behavior could be the transaction handling: maybe RAND is initialized for every transaction / connection and you had different handling in ruby and on the command line. I'd vary this for the tests to see whether it makes any difference. The most likely source for problems is IMHO the implementation of RAND or the handling of "oder by rand() * 10 limit 10". Regards robert