|
CEERAN0
generates a sequence of uniform pseudo-random numbers between 0.0
and 1.0 using the multiplicative congruential method with a user-specified
seed. The uniform (0,1) pseudo-random numbers are generated using
the multiplicative congruential method: seed(i) = (950706376 * seed(i-1)) mod 2147483647;
randomno(i) = seed(i) / 2147483647;
Syntax
>>-CEERAN0--(--seed--,--random_no--,--fc--)--------------------><
- seed (input/output)
- A fullword binary signed integer representing an initial value
used to generate random numbers. seed must
be a variable; it cannot be an input-only parameter. The valid range
is 0 to +2,147,483,646. If seed equals 0,
the seed is generated from the current Greenwich Mean Time. On return
to the calling routine, CEERAN0 changes the value of seed so
that it can be used as the new seed in the next call.
- random_no (output)
- An 8-byte double precision floating-point number with a value
between 0 and 1, exclusive. If seed is invalid, random_no is
set to -1 and CEERAN0 terminates with a non-CEE000 symbolic feedback
code.
- fc (output)
- A 12-byte feedback code, optional in some languages,
that indicates the result of this service. If you choose to omit this
parameter, refer to Invoking callable services for the
appropriate syntax to indicate that the feedback code was omitted.
The
following symbolic conditions can result from this service:
Code |
Severity |
Message number |
Message text |
---|
CEE000 |
0 |
— |
The service completed successfully. |
CEE2ER |
1 |
2523 |
The system time was not available when CEERAN0 was called.
A seed value of 1 was used to generate a random number and a new seed
value. |
CEE2ES |
3 |
2524 |
An invalid seed value was passed to CEERAN0. The random number
was set to -1. |
Usage notes - z/OS UNIX considerations—In
multithread applications, CEERAN0 affects only the calling thread.
The seed is unique to the thread.
Examples - Following is an example of CEERAN0 called by C/C++.
/*Module/File Name: EDCRAN0 */
#include <string.h>
#include <stdio.h>
#include <leawi.h>
#include <stdlib.h>
#include <ceeedcct.h>
int main (void) {
_INT4 seed;
_FLOAT8 random;
_FEEDBACK fc;
int number;
seed = 0;
CEERAN0(&seed,&random,&fc);
if ( _FBCHECK ( fc , CEE000 ) != 0 ) {
printf("CEERAN0 failed with message number %d\n",
fc.tok_msgno);
exit(2999);
}
number = random * 1000;
printf("The 3 digit random number is %d\n",number);
}
- Following is an example of CEERAN0 called by COBOL.
CBL LIB,QUOTE
*Module/File Name: IGZTRAN0
************************************************
** CBLRAN0 - Call CEERAN0 to generate uniform **
** random numbers **
************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. CBLRAN0.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 SEED PIC S9(9) BINARY.
01 RANDNUM COMP-2.
01 FC.
02 Condition-Token-Value.
COPY CEEIGZCT.
03 Case-1-Condition-ID.
04 Severity PIC S9(4) BINARY.
04 Msg-No PIC S9(4) BINARY.
03 Case-2-Condition-ID
REDEFINES Case-1-Condition-ID.
04 Class-Code PIC S9(4) BINARY.
04 Cause-Code PIC S9(4) BINARY.
03 Case-Sev-Ctl PIC X.
03 Facility-ID PIC XXX.
02 I-S-Info PIC S9(9) BINARY.
PROCEDURE DIVISION.
PARA-CBLRAN0.
************************************************
** Specify 0 for SEED, so the seed will be
** derived from the current Greenwich Mean Time
************************************************
MOVE 0 TO SEED.
************************************************
** Call CEERAN0 to return random number between
** 0.0 and 1.0
************************************************
CALL "CEERAN0" USING SEED , RANDNUM , FC.
************************************************
** If CEERAN0 runs successfully, display result.
************************************************
IF CEE000 of FC THEN
DISPLAY "The random number is: " RANDNUM
ELSE
DISPLAY "CEERAN0 failed with msg "
Msg-No of FC UPON CONSOLE
STOP RUN
END-IF.
GOBACK.
- Following is an example of CEERAN0 called by PL/I.
*PROCESS MACRO;
/* Module/File Name: IBMRAN0 */
/****************************************************/
/** **/
/** Function: CEERAN0 - calculate uniform random **/
/** numbers **/
/** **/
/****************************************************/
PLIRAN0: PROC OPTIONS(MAIN);
%INCLUDE CEEIBMAW;
%INCLUDE CEEIBMCT;
DCL SEED REAL FIXED BINARY(31,0);
DCL RANDNUM REAL FLOAT DECIMAL(16);
DCL 01 FC, /* Feedback token */
03 MsgSev REAL FIXED BINARY(15,0),
03 MsgNo REAL FIXED BINARY(15,0),
03 Flags,
05 Case BIT(2),
05 Severity BIT(3),
05 Control BIT(3),
03 FacID CHAR(3), /* Facility ID */
03 ISI /* Instance-Specific Information */
REAL FIXED BINARY(31,0);
SEED = 7; /* Specify an integer as the initial */
/* value used to calculate the random */
/* numbers */
/* Call CEERAN0 to generate random number between */
/* 0.0 and 1.0 */
CALL CEERAN0 ( SEED, RANDNUM, FC );
IF FBCHECK( FC, CEE000) THEN DO;
PUT SKIP LIST ( 'The random number is '
|| RANDNUM );
END;
ELSE DO;
DISPLAY( 'CEERAN0 failed with msg '
|| FC.MsgNo );
STOP;
END;
END PLIRAN0;
|