Results 1 to 3 of 3

Thread: Random numbers.

  1. #1
    Alberto Saynes Guest

    Random numbers.


    I am trying to get random numbers to have a unique value for different processes, then I can identify each process. What happens is that I use rand() function without seed, so I got my random numbers, but after shutting down SQLServer and try to get again another random number after booting up, the same series of random numbers is given again and again. So if anyone knows how I can get unique values,even though reseting the server, and using random function or any other method which automatically provides unique values,I'll really appreciate it if you let me know it.

    This is the function: select rand()

    Alberto.


  2. #2
    Eric Guest

    Random numbers. (reply)

    I have never really dealt with random numbers and SQL Server, but maybe you can use the rand() function combined with the GetDate() and time function to get a true random number. Since the current date and time is constantly changing you should be able to work something pretty unique out.

    E

    ------------
    Alberto Saynes at 6/22/01 9:45:28 AM


    I am trying to get random numbers to have a unique value for different processes, then I can identify each process. What happens is that I use rand() function without seed, so I got my random numbers, but after shutting down SQLServer and try to get again another random number after booting up, the same series of random numbers is given again and again. So if anyone knows how I can get unique values,even though reseting the server, and using random function or any other method which automatically provides unique values,I'll really appreciate it if you let me know it.

    This is the function: select rand()

    Alberto.


  3. #3
    BIll Guest

    Random numbers. (reply)

    If you just want to ensure uniqueness, you could use have a table with a identity column. Just grab the @@indentity. Or you could generate a GUID. Or you could generate a string like 20010101235959555 from datepart()--i.e. date drilled down to the millisecond.

    If you want true randomness, you have to get numbers from quantum decay which are available on the web! (hotbits).


    ------------
    Eric at 6/22/01 5:40:49 PM

    I have never really dealt with random numbers and SQL Server, but maybe you can use the rand() function combined with the GetDate() and time function to get a true random number. Since the current date and time is constantly changing you should be able to work something pretty unique out.

    E

    ------------
    Alberto Saynes at 6/22/01 9:45:28 AM


    I am trying to get random numbers to have a unique value for different processes, then I can identify each process. What happens is that I use rand() function without seed, so I got my random numbers, but after shutting down SQLServer and try to get again another random number after booting up, the same series of random numbers is given again and again. So if anyone knows how I can get unique values,even though reseting the server, and using random function or any other method which automatically provides unique values,I'll really appreciate it if you let me know it.

    This is the function: select rand()

    Alberto.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •