1. Registered User
Join Date
Aug 2006
Posts
2

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.

Balisetty.

2. Registered User
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. Registered User
Join Date
Aug 2006
Posts
2
Thanks a lot.

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

Rgds,
Balisetty

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

Sathyaram

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

6. Registered User
Join Date
Sep 2004
Location
Belgium
Posts
1,126
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.

#### Posting Permissions

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