Must read the content, and let us know your experiences on using
Rand ??
http://www.ezdia.com/My_Sql_Rand%2528%2529_function%252C_limitations_and_usage/Content.do?id=711
Can anyone suggest alternate methods for such functionalities ?
> The RAND function in MySQL is precisely there to prevent this kind of
> problem. Instead of picking a random id with a PHP code, let the
> server do it for you:
>
> Must read the content, and let us know your experiences on using
> Rand? Can anyone suggest alternate methods for such functionalities?
Bypassing a nearly 10K spamdex, the direct link follows:
<http://www.mustap.com/databasezone_post_141_mysql-rand-function>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
As several of the comments on the article pointed out, in many cases
this technique results in a slow, I/O-intensive query (as would
similar
queries on Postgres or Oracle). I can think of reasons to do the
random ID selection in Java code:
* ability to use SecureRandom
* not using a database-specific random-number function
One of the comments had a link to a better explanations of the issues
and
possible solutions; that otehr article tries to to everything in SQL,
but
could be applied to Java:
http://jan.kneschke.de/projects/mysql/order-by-rand/
--
DLL
> On Dec 5, 8:03 am, "John B. Matthews" <nos...@nospam.invalid> wrote:
> > In article
> > <e4e7eb67-fc92-4545-a3f1-107f3687e...@13g2000prl.googlegroups.com>,
> >
> > Weasley <samyaksul...@gmail.com> wrote:
> > > The RAND function in MySQL is precisely there to prevent
> > > this kind of problem. Instead of picking a random id with
> > > a PHP code, let the server do it for you:
>
> As several of the comments on the article pointed out, in
> many cases this technique results in a slow, I/O-intensive
> query (as would similar queries on Postgres or Oracle). I
> can think of reasons to do the random ID selection in Java
> code:
>
> * ability to use SecureRandom
> * not using a database-specific random-number function
>
> One of the comments had a link to a better explanations of
> the issues and possible solutions; that other article tries
> to to everything in SQL, but could be applied to Java:
>
> http://jan.kneschke.de/projects/mysql/order-by-rand/
On the client side, I would add
* client side testing
* distribution sensitive data
Given an instance of Random, it's easy to accumulate a
List<Integer> of ids during initialization and obtain uniform
results with nextInt(ids.size()).