Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Exactly process of Rand() function in MySQL (https://www.warriorforum.com/programming/437133-exactly-process-rand-function-mysql.html)

ebusinessireader 21st August 2011 10:07 PM

Exactly process of Rand() function in MySQL
 
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:

ereadergold 21st August 2011 11:11 PM

Re: Exactly process of Rand() function in MySQL
 
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

ebusinessireader 21st August 2011 11:55 PM

Re: Exactly process of Rand() function in MySQL
 
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?

Thrasher66099 22nd August 2011 08:23 AM

Re: Exactly process of Rand() function in MySQL
 
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.

ebusinessireader 22nd August 2011 10:49 AM

Re: Exactly process of Rand() function in MySQL
 
Quote:

Originally Posted by Thrasher66099 (Post 4518740)
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.... :eek:


All times are GMT -6. The time now is 12:53 PM.