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 10


From: James Lemmon
Subject: Re: [open-cobol-list] open-cobol-list Digest, Vol 68, Issue 10
Date: Fri, 31 May 2013 12:02:01 +0200

Hi,

I don't have OC installed at present as I am building a new PC for it.

However try this as I think that it might resolve the problem

    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 TEST AFTER UNTIL mod-is-10
             COMPUTE temp = FUNCTION RANDOM * 100
             DIVIDE temp BY 20 GIVING div REMAINDER mod
             MOVE mod TO mod-disp
             DISPLAY mod " " mod-disp
         END-PERFORM

         STOP RUN.



On Fri, May 31, 2013 at 5:11 AM, <address@hidden> wrote:
Send open-cobol-list mailing list submissions to
        address@hidden

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.sourceforge.net/lists/listinfo/open-cobol-list
or, via email, send a message with subject or body 'help' to
        address@hidden

You can reach the person managing the list at
        address@hidden

When replying, please edit your Subject line so it is more specific
than "Re: Contents of open-cobol-list digest..."


Today's Topics:

   1. Re: RANDOM-ly non-random (Bruce M. Axtens)
   2. Re: RANDOM-ly non-random (Bruce M. Axtens)
   3. Re: open-cobol-list Digest, Vol 68, Issue 9 (Bruce M. Axtens)
   4. Re: RANDOM-ly non-random (Hiroki MINEMATSU)
   5. Re: open-cobol-list Digest, Vol 68, Issue 9 (Peter Klosky)


----------------------------------------------------------------------

Message: 1
Date: Fri, 31 May 2013 09:53:35 +0800
From: "Bruce M. Axtens" <address@hidden>
Subject: Re: [open-cobol-list] RANDOM-ly non-random
To: Robert Wolfe <address@hidden>,
        "address@hidden"
        <address@hidden>
Message-ID: <address@hidden>
Content-Type: text/plain; charset="iso-8859-1"

On 31/05/2013 12:37 AM, Robert Wolfe wrote:
> Odd, because when I go to compile this code, I get this:
>
> address@hidden:~$ cobc random.cbl
> random.cbl: In paragraph 'Main':
> random.cbl:11: Error: syntax error, unexpected PERFORM, expecting
> ADDRESS or "Identifier"
>
> System is Debian 7 "Wheezy" AMD64 running in an ESXi 5 virtual machine.
Robert

How about
$ cobc -free random.cbl

My compile command in that case was
$ cobc -x -free -I/usr/local/include -L/usr/local/lib random.cbl

-------------- next part --------------
An HTML attachment was scrubbed...

------------------------------

Message: 2
Date: Fri, 31 May 2013 09:57:43 +0800
From: "Bruce M. Axtens" <address@hidden>
Subject: Re: [open-cobol-list] RANDOM-ly non-random
To: Peter Klosky <address@hidden>,       Robert Wolfe
        <address@hidden>,
        "address@hidden"
        <address@hidden>
Message-ID: <address@hidden>
Content-Type: text/plain; charset="iso-8859-1"

On 31/05/2013 4:20 AM, Peter Klosky wrote:
>
> There may be another issue.
>
...
>
> ... neither your machine or mine gives the expected result. ...  Few
> of your results are less than 20; same here.
>
Wow, I was so taken aback by the repetition, I didn't notice the
"failure" of REM. I wonder what's going on?

Bruce.

-------------- next part --------------
An HTML attachment was scrubbed...

------------------------------

Message: 3
Date: Fri, 31 May 2013 10:33:37 +0800
From: "Bruce M. Axtens" <address@hidden>
Subject: Re: [open-cobol-list] open-cobol-list Digest, Vol 68, Issue 9
To: address@hidden
Message-ID: <address@hidden>
Content-Type: text/plain; charset="iso-8859-1"

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.

-------------- next part --------------
An HTML attachment was scrubbed...

------------------------------

Message: 4
Date: Fri, 31 May 2013 11:38:23 +0900
From: Hiroki MINEMATSU <address@hidden>
Subject: Re: [open-cobol-list] RANDOM-ly non-random
To: address@hidden
Message-ID: <address@hidden>
Content-Type: text/plain; charset=UTF-8

Hello, Bruce

OpenCOBOL RANDOM returned biased value.

It is look like conacatinate '0.' and int(rand()*(2**32)) .

so, you execute this.

perl -e '$a = 0; for (1..1000) {$p = int(rand() * (2 ** 31)) ;$a +=
"0.".$p; }; print $a ;print "\n";'

it will show about 347 instead of 500.

Since it is wrong, we have to correct libcob.so.


(2013/05/30 23:30), Bruce M. Axtens wrote:
> Context: MinGW
>
>     $ uname -a
>     MINGW32_NT-6.1 MERCURY 1.0.17(0.48/3/2) 2011-04-24 23:39 i686 Msys
>
>     $ cobc -v
>     cobc (OpenCOBOL) 1.1.0
>     Copyright (C) 2001-2009 Keisuke Nishida / Roger While
>     Built    May 29 2013 21:53:19
>     Packaged Feb 06 2009 10:30:55 CET
>
>
> Sadly, I don't get to do much COBOL. The best I can do is the occasional
> RosettaCode task.
>
> I was looking at <http://rosettacode.org/wiki/Loops/Break#COBOL>. I
> copied and pasted into a text editor, made it free-form, and started to
> fiddle.
>
> I've got as far as this:
>
>     IDENTIFICATION DIVISION.
>     PROGRAM-ID. Random-Nums.
>
>     DATA DIVISION.
>     WORKING-STORAGE SECTION.
>     01    Num  PIC Z9.
>     01    SEED PIC 9V999999999.
>     PROCEDURE DIVISION.
>     Main.
>         MOVE FUNCTION RANDOM(FUNCTION SECONDS-PAST-MIDNIGHT) TO SEED.
>         PERFORM FOREVER
>             PERFORM Generate-And-Display-Num
>
>             IF Num = 10
>                 EXIT PERFORM
>             ELSE
>                 PERFORM Generate-And-Display-Num
>             END-IF
>         END-PERFORM
>
>         GOBACK
>         .
>
>     Generate-And-Display-Num.
>        COMPUTE Num =  FUNCTION REM(FUNCTION RANDOM * 100, 20)
>        DISPLAY Num
>        .
>        END-PROGRAM.
>
> The END-PROGRAM seemed to be mandatory. I wouldn't compile otherwise.
>
> The thing that has me confused (and thus all the fiddling with RANDOM)
> is that the program runs properly occasionally, and other time just gets
> locked on a particular value and doesn't change.
>
> A working runs looks like this:
>
>     $ breakloop.exe
>     23
>     67
>     23
>     21
>     67
>     18
>     14
>     17
>     27
>     11
>     16
>     25
>     29
>     26
>     12
>     23
>     90
>     27
>     14
>     20
>     30
>     29
>     10
>
>
> but another run starts off nicely, but then gets stuck
>
>     $ breakloop.exe
>     25
>     18
>     29
>     80
>     14
>     16
>     26
>     24
>     26
>     36
>     18
>     29
>     54
>     47
>     29
>     29
>     29
>     ... ad infinitum
>
> Why is it so?
>
> Kind regards,
> Bruce.
>
>
>
> ------------------------------------------------------------------------------
> Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
> Get 100% visibility into your production application - at no cost.
> Code-level diagnostics for performance bottlenecks with <2% overhead
> Download for free and get started troubleshooting in minutes.
> http://p.sf.net/sfu/appdyn_d2d_ap1
>
>
>
> _______________________________________________
> open-cobol-list mailing list
> address@hidden
> https://lists.sourceforge.net/lists/listinfo/open-cobol-list
>


--
?? ??    ???????????
850-0057 ?????????11?13?
TEL: 095-840-0021 FAX: 095-895-7869



------------------------------

Message: 5
Date: Thu, 30 May 2013 20:11:11 -0700 (PDT)
From: Peter Klosky <address@hidden>
Subject: Re: [open-cobol-list] open-cobol-list Digest, Vol 68, Issue 9
To: "Bruce M. Axtens" <address@hidden>,
        "address@hidden"
        <address@hidden>
Message-ID:
        <address@hidden>
Content-Type: text/plain; charset="iso-8859-1"

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
-------------- next part --------------
An HTML attachment was scrubbed...

------------------------------

------------------------------------------------------------------------------
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


End of open-cobol-list Digest, Vol 68, Issue 10
***********************************************



--
James Lemmon
Cell +27825663095

reply via email to

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