返回 0 到1 之間的隨機float 值。
RAND ( [ seed ] )
seed
是給出種子值或起始值的整型表達式(tinyint、smallint 或 int)。
float
在單個查詢中反復調用 RAND() 將產生相同的值。
下例產生 4 個通過 RAND 函數產生的不同的隨機值。
DECLARE @counter smallint
SET @counter = 1
WHILE @counter < 5
BEGIN
SELECT RAND(@counter) Random_Number
SET NOCOUNT ON
SET @counter = @counter + 1
SET NOCOUNT OFF
END
GO
下面是結果集:
Random_Number
-------------------
0.71359199321292355
(1 row(s) affected)
Random_Number
-------------------
0.7136106261841817
(1 row(s) affected)
Random_Number
-------------------
0.71362925915543995
(1 row(s) affected)
Random_Number
-------------------
0.7136478921266981
(1 row(s) affected)
相關文章