keyongtech


  keyongtech > php

 #1  
11-24-08, 10:06 PM
Korgan
Hi,

i would ask what is the best method for random select from database. I
have table with 20k items..

- If i use ,,select * from table order by rand() limit 3", the query
took 0.0524 sec ... its slightly enough

- but if i generate rand id and then i use ,,select .... where id
in(rand1, rand2, rand3), the query took only 0.0005 sec, but
there is a problem that id doesnt exist


thanks for responses
 #2  
11-24-08, 10:13 PM
Chris
Korgan wrote:
> Hi,
>
> i would ask what is the best method for random select from database. I
> have table with 20k items..
>
> - If i use ,,select * from table order by rand() limit 3", the query
> took 0.0524 sec ... its slightly enough


and as your table grows in size, it gets slower and slower.

Try this:

http://edrackham.com/featured/get-ra...order-by-rand/

There are other suggestions out there too, search for "mysql don't use
random()".
Similar Threads
Seeding a Pseudo-Random Number Generator (PRNG) from Sources that Aren't Random

We have an embedded product that needs to assign random radio network addresses near startup. We plan to use a PRNG with a period of around 2^32 (with a 32-bit seed). To...

Random phantom breakpoints and random bogus compile errors

We've been getting some strange errors on an Excel VBA project: On random computers, it stops on random lines as if at a breakpoint, but there is no breakpoint there; in...

A random function to fill a buffer with random values would be handy.

Hello, I think the way my applications use random is too slow. Random gets called to fill a byte. Ofcourse I could make my application 4 times faster by filling arrays...

Non-random numbers generated by excel's data analysis random gener

Hi, I've been trying to generate random numbers using excel's random number generator in the analysis toolpak. I'm using Uniform number generation between 0 and 1, and I am...


All times are GMT. The time now is 06:59 PM. | Privacy Policy