But still hope that the veteran veterans more advice, now cut to the chase:
Random function: rand ()
Executing in Query Analyzer: Select rand (), and you can see that the result would be a random decimal like this: 0.36361513486289558,
Decimals like this are not used much in practical applications, and random integers are usually taken from random numbers. Look at the following two methods of randomly taking integers:
1,
A:
The number generated by the Select Floor (rand () *n)---is this: 12.0
B:
Select CAST (Floor (rand () *n) as int)---the number generated is this: 12
2,
The number of A:select ceiling (rand () * N)---Generated is this: 12.0
B:select cast (Ceiling (rand () * N) as int)---the number generated is this: 12
Where the n is an integer you specify, such as 100, you can see that the a method of the two methods is a decimal with a. 0, and the B method is a real integer.
Generally speaking, the two methods are no different, really no difference? There's a little bit of that, that's the range of their generated random numbers:
The number range of Method 1:0 through N-1, such as CAST (Floor (rand () *100) as int), generates any integer between 0 and 99
Method 2 has a range of digits between 1 and N, such as cast (ceiling rand () () as int), which generates any integer between 1 and 100
For this distinction, look at SQL's online Help for a cicada:
------------------------------------------------------------------------------------
Compare CEILING and FLOOR
The CEILING function returns the smallest integer that is greater than or equal to the given numeric expression. The FLOOR function returns the largest integer less than or equal to the given numeric expression. For example, for numeric expression 12.9273,ceiling will return 13,floor will return 12. The data types of the FLOOR and CEILING return values are the same as the data types of the numeric expressions entered.
----------------------------------------------------------------------------------
Now, you can use these two methods to get a random number of ^_^
In addition, but also to remind you rookie, about random access to any of the table N Records of the method, very simple, with newid ():
Select Top N * NEWID ()----n is an integer that you specify, and the table is the number of bars to get the record table_name
OK, this article is written here