by Robert Sample » Thu Nov 10, 2016 11:09 pm
The Enterprise COBOL Language Reference manual tells you plenty about the seed for RANDOM:
The seed value can be whatever you want between 0 and 2147483645 (in COBOL 5.1).
The seed value is only needed for the first use of RANDOM; after that, if no parameter is passed to RANDOM the next value in the current sequence will be returned.
If you don't specify a seed value the first call, RANDOM uses zero.
For any given seed value, the pseudorandom sequence returned will be the same.
So for simplicity of testing you probably want to use a constant for the seed value; for your actual run(s) you probably want to use something that will vary (based on time, for example -- calculate seconds elapsed today / this week / this month or this year). Note that the value returned by RANDOM needs to be stored in a COMP-1 or COMP-2 variable since it represents a floating point value between 0 and 1.
Cosine varies from +1 to -1 (which is a range of 2), so convert the pseudorandom value by multiplying it by 2 and subtracting 1 from it (this converts a value in the range 0 to 1 to a value in the range -1 to +1).
- These users thanked the author Robert Sample for the post:
- rakesh082 (Mon Nov 14, 2016 5:41 pm)