In mysql, the Rand () function is used to query random data in a data table. However, the Rand () function uses tens of thousands of records quickly, if tens of millions of records may cause problems, let's introduce the usage of the Rand () function.
MySQL randomly queries a record.
The Code is as follows:
Copy code
$ SQL = "SELECT * FROM
I always thought that mysql would randomly query several pieces of data.SELECT * FROM 'table' order by rand () LIMIT 5You can.However, the test results show that the efficiency is very low. It takes more than 8 seconds to query 5 data records in a database with more than 0.15 million entriesAccording to the official manual, rand () is executed multiple times in the order by clause, which is naturally ineffi
I always thought that MySQL would randomly query several pieces of data.
Select * From 'table' order by rand () limit 5You can.However, the test results show that the efficiency is very low. It takes more than 8 seconds to query 5 data records in a database with more than 0.15 million entries
According to the official manual, Rand () is executed multiple times in the order by clause, which is naturally inef
It can be considered that rand () is viewed every time it is called:1) If you have previously called srand (SEED) and specified a value for seed, it will automatically callSrand (SEED) is used once to initialize its starting value.2) If you have not called srand (SEED) before, it will automatically call srand (1) once.
1) If you want rand () to generate different values each time the program runs, you must
The following articles mainly introduce the Efficiency Test of using rand random query records in MySQL databases. I believe that if you have mastered the technology of using the rand random query record efficiency test in MySQL databases, it will be of great help in future studies or work.
I always thought that MySQL would randomly query several pieces of data.
SELECT*FROM`table`ORDERBYRAND()LIMIT5
Transferred from: http://database.51cto.com/art/201009/224397.htmThe following will introduce you to the random function rand () in SQL, for your reference, if you are new to SQL Server, you might want to look at it and believe it will help you learn about the functions in SQL.In SQL Server, there is a random function rand (), some novice may not know the existence of this function, and now I will be the fu
PHP Functions Rand and Mt_rand
Mt_rand () four times times faster than Rand ()
Many old libc random number generators have some uncertainties and unknown properties and are slow. The rand () function of PHP uses the libc random number generator by default. The Mt_rand () function is used informally to replace it. The function uses the known characterist
The mysql tutorial does not use the rand () function to randomly read database tutorial records.As well as google's related files, we found that order by rand () is almost the same, but there are actually very serious performance problems.If your database contains only a few hundred entries and the number of calls is small, you can use whatever method you like.However, if you have 0.1 million or 1 million o
Functions rand () and mt_rand (), randmt_rand
The rand () function is used to obtain random numbers:
Rand () can be set to 0 or two parameters, such as rand ($ min, $ max). $ min indicates that the value starts from XX, and $ max indicates that the maximum value can only be XX.
For example:
Mt_rand () is similar
Intelligence on computersAlgorithm(GA, PSO, Ann etc.) randomly generated during simulationInitial population(Initial sample), let's take a look atPseudo-Random NumberGenerate it ~~~
1. Generate a real number and an integer between [a, B]
/* Defines the int rand (void) function. It indicates that rand () returns a random value ranging from 0 to rand_max. Before calling this function to generate a rando
Rand () Definition: returns a random floating point value from 0 to 1.
Example:
Select rand () as random number result
Select cast (floor (RAND () * n) as INT) -- Method 1
Result: 47
Select cast (celing (RAND () * n) as INT) -- method 2
Result: 47
Generally, there is no difference between the two methods. The
(); // seeding for the random number generator$ Randval = mt_rand (); // generates a random number.Echo $ randval; // output result/*The rand () function returns a random integer.SyntaxRand (min, max) parameter descriptionMin, max (optional. Specifies the range of random numbers.DescriptionIf the optional parameters min and max are not provided, rand () returns a pseudo-random integer between 0 and rand_ma
The rand () function returns a random integer.SyntaxRand (min, max) parameter descriptionMin, max (optional. Specifies the range of random numbers.If no optional parameter is providedMinAndMax, Rand () returns a pseudo-random integer between 0 and RAND_MAX. For example, if you want a random number between 5 and 15 (including 5 and 15), use rand (5, 15 ).To genera
This long-name postA random function generated by Rand increases progressively.And the teacher said, "Because the time of two adjacent loops is less than 1 second, the seed value is the same, so the random number is the same ", it aroused my interest in rand. Just a few days ago, I saw some implementations of the C programming language: Unsigned long int next = 1; //
See Rand () in the function quick check:1#include 2#include 3 4 intMainvoid) 5 { 6 inti;7 8printf"Ten random numbers from 0 to 99\n\n"); 9 for(i=0; iTen; i++) Tenprintf"%d\n",rand ()%); One return 0; A}Can generate 10 random numbers.The beginning does not understand the place: rand ()%100 What do you mean? The →%100 can guarantee that the random numbe
Execute in Query Analyzer: Select rand (), you can see that the result is similar to a random decimal: 0.36361513486289558, a decimal like this is used in the actual application is not much, generally to take random numbers will take random integers. Let's look at the following two methods of randomly taking integers:1.A:The number---generated by select Floor (rand () *n) is like this: 12.0B:Select CAST (*n
Need to test the MySQL database, which has a database of tens of thousands of data, how to write a PHP file every time update hundreds of information, I am writing a cycle to update a message, so I know with a while to write on it, if an update like 100 data changes how to write it! The correct answer is to use the MySQL rand function: UPDATE cdb_posts SET views = rand (); and I got you some examples of the
According to the official documentation, RAND () has a value range of [0,1]In MySQL, you can perform the following commands to view:Mysql>?RandName:'RAND'Description:syntax:RAND(),RAND(N)ReturnsA random floating-Point value VinchTherange 0 .IfaconstantintegerArgument N isspecified, it isUsed asThe seed Value,which produces aRepeatableSequence of column Values.inchthe Followingexample, note that the sequence
The Srand function is the initialization function of the random number generator. Prototype:voidsrand (unsigned int seed);Srand and Rand () work together to produce a sequence of pseudo-random numbers. The RAND function requires a system-supplied seed to generate a sequence of pseudo-random numbers before generating a random number, and Rand produces a series of
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.