Jump to content

Need faster alternative to RAND()


ableroos

Recommended Posts

I am combining 2 words out of a table with about 60,000 rows to create random names. I have used RAND() but it is way too slow.

 

Here is my code:

 

$sqlquery = "SELECT text FROM words ORDER BY RAND() LIMIT 2";

$results  = mysql_query($sqlquery);

  while ($row = mysql_fetch_array($results, MYSQL_NUM)) {

      echo strtoupper ($row[0] . " " . $row[1]);

  }

 

Can anyone suggest a faster alternative and show me an example?

 

Thanks

Link to comment
Share on other sites

The problem with the solutions on that page is all the selections end up pulling from the same region of the database so word 1 is always a word beginning with "A" and the second word is almost always word that begins with A as well or perhaps a "B". They are random, but not very random if that makes sense.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.