What is the standard COBOL RANDOM function implementation?

442 views Asked by At

The COBOL RANDOM function documentation doesn't give sufficient information on the range of accepted values for argument-1.

Perhaps someone can shed light on my following questions:

  • What range of seed values is accepted?
  • How are values treated that are exceeding the allowed range?
    • Are they truncated?
    • Are only the lower bits used?
    • Or the upper bits?
    • Are the leftmost digits used?
    • Or the rightmost?
    • How many of them?
    • Is a MOD function applied to the seed value?

In short:

Is there a specification in the COBOL standard defining which digits of a value like 01 myRandomSeed PIC 9(50). are being used?


Large value demonstration

1

There are 1 answers

1
Simon Sobisch On BEST ANSWER

For the COBOL standard have a look at the current draft standard (the files available there vary depending on the current state of the committee work), which has the RANDOM function under "15 intrinsic functions".

The format is:

FUNCTION RANDOM [ (  [ argument-1 ]  ) ]

With the rules that the optional argument-1 shall be of class numeric and either be zero or a positive integer.

For the returned value:

The implementor shall specify the subset of the domain of argument-1 values that will yield distinct sequences of pseudo-random numbers. This subset shall include the values from 0 through at least 32767.