gnucobol-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [open-cobol-list] open-cobol-list Digest, Vol 68, Issue 9


From: Peter Klosky
Subject: Re: [open-cobol-list] open-cobol-list Digest, Vol 68, Issue 9
Date: Thu, 30 May 2013 20:11:11 -0700 (PDT)

Bruce,
 
To me, your result looks right.
 
The code is designed to quit only when the first of two generated numbers is ten.  In your example, result six is ten, which is not the terminating condition.  Result twenty-one is also ten, which is the terminating condition.
 
I ran a few dozen trials of your improved code.  Works great.  Quit after an odd number of random numbers every time.
 
thanks,
 
Peter 

From: Bruce M. Axtens <address@hidden>
To: address@hidden
Sent: Thursday, May 30, 2013 10:33 PM
Subject: Re: [open-cobol-list] open-cobol-list Digest, Vol 68, Issue 9

I've been fiddling with this a bit more and now have something that appears to work 90% of the time.
IDENTIFICATION DIVISION.
PROGRAM-ID. Random-mod-disps.

DATA DIVISION.
WORKING-STORAGE SECTION.
01    mod-disp      PIC Z9.
01    seed     PIC 999V999.
01    temp    PIC 999V.
01    div        PIC 99.
01    mod        PIC 99.
    88    mod-is-10 value 10.
PROCEDURE DIVISION.
Main.
    MOVE FUNCTION RANDOM(FUNCTION SECONDS-PAST-MIDNIGHT) TO seed.
    PERFORM FOREVER
        PERFORM Generate-And-Display-mod-disp

        IF mod-is-10
            EXIT PERFORM
        ELSE
            PERFORM Generate-And-Display-mod-disp
        END-IF
    END-PERFORM

    STOP RUN.
    .

Generate-And-Display-mod-disp.
    COMPUTE temp = FUNCTION RANDOM * 100.
    DIVIDE temp BY 20 GIVING div REMAINDER mod.
    MOVE mod TO mod-disp.
    DISPLAY mod " " mod-disp.
    .
  
Compiled with $ cobc -x -free -I/usr/local/include -L/usr/local/lib  breakloop.cob

The other 10% is where a run calculates a mod of 10 but does not exit the perform, viz
address@hidden ~/open-cobol-1.1
$ breakloop.exe
05  5
02  2
03  3
00  0
12 12
10 10
11 11
12 12
08  8
13 13
15 15
19 19
19 19
11 11
02  2
09  9
05  5
14 14
15 15
15 15
10 10

Please note the 6th line which says that mod contains 10 and mod-disp contains 10. Instead of terminating then, the program continues on until it hits another 10 10 pair and *then* it terminates.

What's going on here?

Bruce.


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
_______________________________________________
open-cobol-list mailing list
address@hidden
https://lists.sourceforge.net/lists/listinfo/open-cobol-list



reply via email to

[Prev in Thread] Current Thread [Next in Thread]