If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Random Number

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-31-06, 13:23
Balisetty Balisetty is offline
Registered User
 
Join Date: Aug 2006
Posts: 2
Question 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.
Reply With Quote
  #2 (permalink)  
Old 09-01-06, 04:04
umayer umayer is offline
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
Reply With Quote
  #3 (permalink)  
Old 09-01-06, 04:41
Balisetty Balisetty is offline
Registered User
 
Join Date: Aug 2006
Posts: 2
Thanks a lot.

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



Rgds,
Balisetty
Reply With Quote
  #4 (permalink)  
Old 09-01-06, 05:34
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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.
Reply With Quote
  #5 (permalink)  
Old 09-01-06, 08:21
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
Do the random numbers have to all be different? Do they have to be unique?
Reply With Quote
  #6 (permalink)  
Old 09-03-06, 02:48
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
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/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On