Subject: | |
From: | |
Reply To: | |
Date: | Wed, 28 Feb 2001 14:52:04 -0800 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
Curt writes:
> I need to write a COBOL program that generates a random number
> (to use in a voter registration system). I can't seem to find
> any reference on how to do this in COBOL.
"Anyone who considers arithmetical methods of producing random
numbers is, of course, in a state of sin." -- John Von Neumann
See the first third of Knuth volume 2:
http://www.amazon.com/exec/obidos/ASIN/0201896842
It really depends on how "good" you need your random numbers to be. The
standard 3000 way of generating random numbers is to call the old Compiler
Library routine RAND, which I assume is a linear congruential random number
generator (but I don't know if it is a "good" one or a "bad" one). Of
course the problem for COBOL is that RAND and its kin produce floating point
results which COBOL won't natively handle. A typical solution is to write a
subroutine in some other language or to explicitly code a call to one of the
HP type conversion Intrinsics.
And heck, maybe COBOL has a standard random number function by now that I
don't know about.
But generating and using random numbers for serious purposes is one of those
things like cryptography that can look simple, but really requires some
professional skills in math and statistics if you want to be sure what
you're doing is valid.
G.
|
|
|