How To Generate Random Numbers with the RAND() Function in MS SQL Server?
Random numbers are very useful for generating test data, passwords, or other security related data. SQL Server 2005 offers you the random number generator function RAND in two format: * RAND(seed) – Starting a new sequence of random numbers based on the given integer “seed” and returning the first random number in FLOAT(53) from the sequence. * RAND() – Returning the next random number in FLOAT(53) from the current sequence. If there has been no current sequence, SQL Server will start a new sequence with a random “seed”. Note that calling RAND(seed) with the same seed will start the same sequence and return the same number. To avoid this repeating pattern, you should always call RAND() without any seed and let the server to randomly pickup a sequence. The tutorial exercise below shows some good examples on how to generate random numbers: SELECT RAND(100), RAND(), RAND(); — new sequence SELECT RAND(100), RAND(), RAND(); — same sequence again SELECT RAND(), RAND(), RAND(); SELECT RAND(
Related Questions
- I added page numbers to my proposal document in MS Word™, but when I converted it to .PDF format, the formatting changed. What should I do?
- Does the user need to purchase and install the MS SQL server license prior to installing MiMiC v3?
- How To Generate Random Numbers with the RAND() Function in MS SQL Server?