Results 1 to 6 of 6

Thread: Random Number

  1. #1
    Join Date
    Aug 2006
    Posts
    2

    Question Unanswered: Random Number

    Hi,

    I need a Ref. num CHAR(16) out of which the first 3 Chars I am using to specify the type of the Process. The remaining I am using to have a Random number.

    Somebody please specify what is the best logic I can follow as my system is going to face a big load. I want my Random number to be as best as possible.


    Thanks in Advance.

    Balisetty.

  2. #2
    Join Date
    Dec 2005
    Posts
    273
    DB2 provides a function RAND() which generates a random number.
    To convert that number into a char(13) string, you might use:

    SUBSTR(CAST(RAND() AS CHAR(15) ),3,13)

    Just try it:
    SELECT SUBSTR(CAST(RAND() AS CHAR(15) ),3,13)
    FROM SYSIBM.SYSDUMMY1

  3. #3
    Join Date
    Aug 2006
    Posts
    2
    Thanks a lot.

    Is there any alternate / better way of doing the same ?



    Rgds,
    Balisetty

  4. #4
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    What about using the microsecond part of the current time ???

    Sathyaram
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  5. #5
    Join Date
    Aug 2004
    Posts
    330
    Do the random numbers have to all be different? Do they have to be unique?

  6. #6
    Join Date
    Sep 2004
    Location
    Belgium
    Posts
    1,126
    Quote Originally Posted by urquel
    Do the random numbers have to all be different? Do they have to be unique?
    A random number sequence should guarantee independence of its elements. Unicity is not a criterion: by coincidence two numbers might be identical, and the probability of this to occur should be exactly equal to 1/n, where n is the number of different random numbers that can be generated (in case of a uniformly distributed random number, which is most often what people want).
    "Independence" means that e.g. the value of the second number is not influenced by the first one, i.e., that it has probability 1/n of being any of the n possibly outcomes, just like the first one had.
    --_Peter Vanroose,
    __IBM Certified Database Administrator, DB2 9 for z/OS
    __IBM Certified Application Developer
    __ABIS Training and Consulting
    __http://www.abis.be/

Posting Permissions

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