Operating System - OpenVMS
1827372 Members
4533 Online
109963 Solutions
New Discussion

Generating a random number in DCL

 
Niall Godwin
Advisor

Generating a random number in DCL

I want to generate a 7 digit random number in DCL and assign it to a symbol.
Can anybody help ?
5 REPLIES 5
Jan van den Ende
Honored Contributor

Re: Generating a random number in DCL

Niall,

how random do you need it?

In cases like this I usually let the system clock work for me.
Mind: use SEPARATE F$CVT calls!
Note: spacing around single & double quotes for readability only. Remove in code.
$ one = f$cvtime( "" ,, " hundredth " )
$ two = f$cvtime( "" ,, " second " )
$! need odd number of digits:
$ two = f$extract(1,1, " ' ' two ' " )
$ three = f$cvtime( "" ,, " hundredth " )
$ wait 0:0:0. ' two '
$ four = f$cvtime( "" ,, " hundredth " )
$
$ rand = " ' ' one' ' ' two ' ' ' three ' ' ' four ' "

Make this a subroutine, and re-activate at each need of rand

hth

Proost.

Have one on me.

jpe



Don't rust yours pelled jacker to fine doll missed aches.
Hein van den Heuvel
Honored Contributor

Re: Generating a random number in DCL


Watch out (sic) using just the clock, of system page faults, or such as a seed, as it may readily result in steady progression in the low order digits.

------ from an old note by 'mulp' ----------
The following seems to be the best compromise between performance and the
generally accepted recommendations. While the top two bits are discarded,
the next 5-10 bits are used for calculating a number from 0 to range-1.

$ seed = seed*69069 + 1 ! alternate $ seed = seed*987654317 + 1
$ value = (seed.and.%x3FFFFFFF)/(%x40000000/range)
---------------------------------------
If you want repeatable random, then pick the same seed every time. If not, seed with time or pagefaults, or whatever.


hth,
Hein.


Karl Rohwedder
Honored Contributor

Re: Generating a random number in DCL

I once 'found' the attached DCL routine, which incorporates a random generator, pls. read
the comments at the beginning.

regards Kalle
Niall Godwin
Advisor

Re: Generating a random number in DCL

Thanks for your help guys.
Niall.
Niall Godwin
Advisor

Re: Generating a random number in DCL

The clock solution is the simplest, and provides sufficient randomness for my needs.