RAND functionI have searched in the web and couldn't find any details. Some people believe that the RAND function is not fully random and by having enough sample they can predict the next one.
The RAND() generates numbers based on the seed parameter.
Syntax: RAND ( [ seed ] )
Per MSDN,
RAND() is called with a specified seed value, all subsequent calls of RAND() produce results based on the seeded RAND() call.For example, if you run this code in multiple connections (even on multiple databases or database servers at different times)
SELECT RAND(100), RAND(), RAND()
you will get same results, below.
(No column name) (No column name) (No column name)
0.715436657367485 0.28463380767982 0.0131039082850364
So if some one can predict the seed value you used, they may be able to guess resulting random numbers.
That should confirm that RAND() definitely does not use time or mac address kind of inputs into the algorithm.
This page at sql-server-helper.com suggests using NEWID() as the better way of generating unique random numbers. But NEWID() is available on SQL 2008 or later.
SELECT ABS(CAST(CAST(NEWID() AS VARBINARY) AS INT)) AS [RandomNumber]
Disclaimer: I am not associated with www.sql-server-helper.com.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With