Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Random number generation with PL/I program.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
satish.ms10

Active User


Joined: 10 Aug 2009
Posts: 158
Location: India

PostPosted: Wed Jul 21, 2010 2:48 pm    Post subject: Random number generation with PL/I program.
Reply with quote

Hi,

I have written a small program to generate random number in PL/I.

Here is the code:

Code:

 TEST888: PROC OPTIONS(MAIN);

  DCL
     RANDVAL    FLOAT DEC(2);
 
  DECLARE RANDOM                  GENERIC (
     RANDOM0                      WHEN ( ),
     RANDOM1                      WHEN (*) );
 
  DCL SYSPRINT STREAM FILE;
 
  DO I=1 TO 5;
    RANDVAL=RANDOM();
    PUT SKIP LIST ('RANDOM NUMER:',RANDVAL);
  END;

  PUT SKIP LIST ('END...');

 RANDOM0:
   PROCEDURE                       RETURNS (FLOAT BINARY (53) );
      DECLARE R_SEED               EXTERNAL STATIC FIXED BINARY (31)
                                   INITIAL (1);
      RETURN (RANDOM(R_SEED));
   END  RANDOM0;

 (NOSIZE, NOFIXEDOVERFLOW):
 RANDOM1:
   PROCEDURE (SEED)                RETURNS (FLOAT BINARY (53));
      DECLARE SEED                 FIXED BINARY (31);
      DECLARE R_SEED               EXTERNAL STATIC FIXED BINARY (31)
                                   INITIAL (1);
      DECLARE (UNSPEC, ABS)        BUILTIN;
      DECLARE CHOPPER              FIXED BINARY (31) STATIC
                                   INITIAL (2147483647);
 

      IF SEED <= 0 THEN SIGNAL ERROR;
      IF SEED >= 2147483646 THEN SIGNAL ERROR;
      SEED = SEED * 5 - 3;
      IF SEED < 0 THEN
         SEED = (SEED + CHOPPER) + 1;
      IF SEED < 0 THEN
         UNSPEC (SEED) = UNSPEC (SEED) & UNSPEC (CHOPPER);
      IF SEED < 0 THEN
         SEED = ABS(SEED);
      R_SEED = SEED;
      RETURN (SEED/2147483648E0);
   END  RANDOM1;
 
  END TEST888;


Output of the above program is like below:

Code:

********************************* TOP OF DATA **********************************
RANDOM NUMER:            9.3E-10
RANDOM NUMER:            3.2E-09
RANDOM NUMER:            1.4E-08
RANDOM NUMER:            7.3E-08
RANDOM NUMER:            3.6E-07
END...
******************************** BOTTOM OF DATA ********************************


But I the expected results are
Code:

********************************* TOP OF DATA **********************************
RANDOM NUMER:            9
RANDOM NUMER:            3
RANDOM NUMER:            1
RANDOM NUMER:            7
RANDOM NUMER:            3
END...
******************************** BOTTOM OF DATA ********************************


Could you please let me know what change I need to do to get desired results?

Kindly let me know if we have any other way to generate random number in PL/I program.

Awaiting your kind reply.

Thanks in advance.
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10234
Location: italy

PostPosted: Wed Jul 21, 2010 2:58 pm    Post subject: Reply to: Random number generation with PL/I program.
Reply with quote

start from
http://www-03.ibm.com/systems/z/os/zos/bkserv/index.html

proceed to Your zOS bookshelf ( for example )
http://www-03.ibm.com/systems/z/os/zos/bkserv/zshelves9.html

anf the to the Language environment bookshelf
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/Shelves/CEE2BK80

search for random or CEERAN0 ( I knew what to search for ) and ...
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ceea3180/2.2.5.61?ACTION=MATCHES&REQUEST=ceeran0&TYPE=FUZZY&SHELF=CEE2BK80.bks&DT=20070428023816&CASE=&searchTopic=TOPIC&searchText=TEXT&searchIndex=INDEX&rank=RANK&ScrollTOP=FIRSTHIT#FIRSTHIT

better to use a standard method rather than using Your own
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1005
Location: Oostende, Belgium

PostPosted: Wed Jul 21, 2010 8:33 pm    Post subject: Re: Random number generation with PL/I program.
Reply with quote

satish.ms10 wrote:
Hi,

I have written a small program to generate random number in PL/I.


Wow, and it doesn't even work...

Next time, RTFM, PL/I, since at least Enterprise PL/I V3R5, has a builtin with the rather obvious name "RANDOM", which generates a FLOAT BIN (53) pseudo-random number between 0 and 1.
Back to top
View user's profile Send private message
satish.ms10

Active User


Joined: 10 Aug 2009
Posts: 158
Location: India

PostPosted: Thu Jul 22, 2010 12:29 pm    Post subject:
Reply with quote

Hi Prino,

I have gone thru the manual and used RANDOM function but it is giving errors at the time of compilation

My code is:

Code:

DCL
   RAND2      ENTRY,
   RAND3      FLOAT DEC(10),
   RANDVAL    FLOAT DEC(2);

DECLARE RANDOM                  GENERIC (
   RAND2                        WHEN (FIXED),
   RAND3                        WHEN (FLOAT) );

DO I=1 TO 5;
  RANDVAL=RANDOM(1);
  PUT SKIP LIST ('RANDOM NUMER:',RANDVAL);
END;


The error messages which I get at the time of compilation are:
Code:

COMPILER DIAGNOSTIC MESSAGES
ERROR ID L   STMT    MESSAGE DESCRIPTION

SEVERE AND ERROR DIAGNOSTIC MESSAGES

IEL0445I S   4       'RAND3' IN 'GENERIC' SPECIFICATION IS NOT AN ENTRY NAME AND IS IGNORED.


Could you please let me know how to declare and use this function?

Thanks in advance.
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1005
Location: Oostende, Belgium

PostPosted: Thu Jul 22, 2010 12:36 pm    Post subject:
Reply with quote

satish.ms10 wrote:
I have gone thru the manual and used RANDOM function but it is giving errors at the time of compilation

My code is:

Code:

DCL
   RAND2      ENTRY,
   RAND3      FLOAT DEC(10),
   RANDVAL    FLOAT DEC(2);

DECLARE RANDOM                  GENERIC (
   RAND2                        WHEN (FIXED),
   RAND3                        WHEN (FLOAT) );

DO I=1 TO 5;
  RANDVAL=RANDOM(1);
  PUT SKIP LIST ('RANDOM NUMER:',RANDVAL);
END;


The error messages which I get at the time of compilation are:
Code:

COMPILER DIAGNOSTIC MESSAGES
ERROR ID L   STMT    MESSAGE DESCRIPTION

SEVERE AND ERROR DIAGNOSTIC MESSAGES

IEL0445I S   4       'RAND3' IN 'GENERIC' SPECIFICATION IS NOT AN ENTRY NAME AND IS IGNORED.


Could you please let me know how to declare and use this function.


Is
Code:
dcl random builtin;
too hard to understand for you gray cell?
Back to top
View user's profile Send private message
satish.ms10

Active User


Joined: 10 Aug 2009
Posts: 158
Location: India

PostPosted: Thu Jul 22, 2010 1:10 pm    Post subject:
Reply with quote

Hi Prino,

We are having "IBM PL/I for MVS & VM Ver 1 Rel 1" at our shop.

So I got code sample (which I mentioned in the beginning of this post) to generate random number from google. That code is giving following results

Code:

RANDOM NUMER:            9.3E-10
RANDOM NUMER:            3.2E-09
RANDOM NUMER:            1.4E-08
RANDOM NUMER:            7.3E-08
RANDOM NUMER:            3.6E-07
END...


Which I want output as a whole number. Could you please suggest me where I need to do changes to my code? and what change it is?

Kindly advise me.
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1005
Location: Oostende, Belgium

PostPosted: Thu Jul 22, 2010 1:18 pm    Post subject:
Reply with quote

"The number is too small!"

Ever thought of multiplying it by a suitable factor? Holy sith, are you really this thick, or just pretending?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8003
Location: Bellevue, IA

PostPosted: Thu Jul 22, 2010 4:54 pm    Post subject:
Reply with quote

Either you're a student or you slept through your programming classes (or they've changed the classes drastically from when I was in school). My classes taught me the output of a random number generator was a value uniformly distributed between zero and one. So I wanted a throw of a die, I'd multiply the random number by six, add one, and take the integer value. And this was taught in multiple programming classes.
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 962
Location: Richmond, Virginia

PostPosted: Thu Jul 22, 2010 5:02 pm    Post subject:
Reply with quote

I don't understand why the OP's orig numbers all have large negative exponents - even those are not uniform between 0-1. Was that not the intended interval?

This question, seems to me, needs an answer before converting to an integer range. (Or, of course, the correct answer above - use the BUILTIN function.)

I must have missed something here.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts what is meaning of the number in dcl Martylin PL/I & Assembler 2 Thu Mar 09, 2017 7:18 am
No new posts Extract set of records matching on ac... bhaskar_kanteti DFSORT/ICETOOL 3 Mon Mar 06, 2017 7:19 am
No new posts GDG version number PANDU1 JCL & VSAM 4 Sat Mar 04, 2017 8:28 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us