In my earlier articles, we have seen how to use RAND and NEWID. Now we will compare RAND() vs NEWID() and understand the major differences between them.
RAND() vs NEWID()
# | RAND() | NEWID() |
---|---|---|
1 | Used to generate random numbers. | Used to generate GUID. |
2 | Returns a pseudo random float value ranging between 0 and 1. | Returns a value of type uniqueidentifier. |
3 | Example value from RAND(): 0.713666525097956 | Example value from NEWID(): 52332A28-22B8-414D-8791-423EFFFDF9F1 |
4 | You can apply some formula and make it to return random integer or float between a range of numbers. | You can CAST and then apply some formula and make it to return random integer or float between a range of numbers. |
5 | Does not follow any specific standards. | Follows RFC 4122 standards. |
Reference
- About NEWID() at Microsoft Words.
- About RAND() at Microsoft Words.