Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 21st Aug 2011, 10:07 PM   #1
Do not try to find me.
 
Join Date: 2011
Posts: 62
Thanks: 0
Thanked 3 Times in 3 Posts
Default
Exactly process of Rand() function in MySQL
Share on: 
fb share twitter share gplus share more share

Does anyone know, what is the exactly process of Rand() function in MySQL.

I see a lot of people are trying to do random row with some other method.

How much does it improve performance, Compared with "ORDER BY RAND()" methods.

:confused::confused::confused:
ebusinessireader is offline  
Unread 21st Aug 2011, 11:11 PM   #2
VIP Warrior
War Room Member
 
ereadergold's Avatar
 
Join Date: 2008
Location: Montreal Canada
Posts: 2,390
Thanks: 1,017
Thanked 836 Times in 572 Posts
Blog Entries: 1
Default
Re: Exactly process of Rand() function in MySQL
Share on: 
fb share twitter share gplus share more share

The advantage of using RAND() is really portability between the different platforms and programming languages that support MySQL. It is not the most efficient process, which is why you see several random number generators implemented in external code.

Here is a link to an article about doing it with MySQL, the author gives performance comparisons with doing it his way vs using RAND().

Get Random Row with MySQL Without ORDER BY RAND() - edrackham

Bill
ereadergold is offline  
Unread 21st Aug 2011, 11:55 PM   #3
Do not try to find me.
 
Join Date: 2011
Posts: 62
Thanks: 0
Thanked 3 Times in 3 Posts
Default
Re: Exactly process of Rand() function in MySQL
Share on: 
fb share twitter share gplus share more share

I just noticed that. >_@
By "order by rand()" in sql command
it's not really random everytime of refreshing page.
I mean, it has delay period before new random row by database.

Am I Right?
ebusinessireader is offline  
Unread 22nd Aug 2011, 08:23 AM   #4
The king of swing
 
Thrasher66099's Avatar
 
Join Date: 2011
Location: Romeoville, IL
Posts: 142
Thanks: 0
Thanked 17 Times in 15 Posts
Default
Re: Exactly process of Rand() function in MySQL
Share on: 
fb share twitter share gplus share more share

I haven't looked at mysql directly, but I can tell you that most programming languages use the system clock for their rand functions. This means that your rand really won't be that random if it happens multiple times in a row. In fact, it's very likely that you'll get multiple values that are the same if the rand funtion completes multiple times before the clock cycle finishes. That is the biggest reason that most people write their own randomization functionality.

Thrasher66099 is offline  
Unread 22nd Aug 2011, 10:49 AM   #5
Do not try to find me.
 
Join Date: 2011
Posts: 62
Thanks: 0
Thanked 3 Times in 3 Posts
Default
Re: Exactly process of Rand() function in MySQL
Share on: 
fb share twitter share gplus share more share

Originally Posted by Thrasher66099 View Post

I haven't looked at mysql directly, but I can tell you that most programming languages use the system clock for their rand functions. This means that your rand really won't be that random if it happens multiple times in a row. In fact, it's very likely that you'll get multiple values that are the same if the rand funtion completes multiple times before the clock cycle finishes. That is the biggest reason that most people write their own randomization functionality.
Oh....
ebusinessireader is offline  
Closed Thread


Bookmarks

Tags
function, mysql, process, rand, random


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 05:20 PM.