HP3000-L Archives

October 1997, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Reply To:
Date:
Tue, 21 Oct 1997 16:01:39 PST8
Content-Type:
text/plain
Parts/Attachments:
text/plain (122 lines)
If the function/intrinsic indicated by Steve bears any resemblance to their
counterparts in the CM world of the HP3000 then let me elaborate a bit.

There exists a function, RAND, that typically is used to get a 'seed' number
for the random number generator intrinsic.  The returned data if a floating
point type, a bit hard to represent in COBOL.  There also exists an
intrinsic, RAND1(seed#) that also returns a floating point value 0.0<=x<=1.0.

The code that follows is from a simple routine that displays the quote of the
day.

...
PROGVAR
  PV'RLEN             N02;
  PV'FNUM             N02;
  PV'FSIZE            N10;
  PV'FRECORD          N10;
  PV'SEED             F6.6;
  PV'RAND'NO          F6.6;

  PV'FNAME            A20;

FUNCTION RAND (BY REF seed F6.6) F6.6 IS SPL-EXTERNAL;

INTRINSIC
  FOPEN
 ,FREADDIR
 ,FREAD
 ,FCLOSE
 ,TERMINATE
 ,PRINTFILEINFO
 ,FFILEINFO
 ,RAND1
 ;

BEGIN

  PV'VERSE'EDGE= FALSE;
  PV'FNAME    = "QUOTEF; ";
  PV'FNUM     = FOPEN (PV'FNAME,%7,%340); <<Open the file and >>
  IF CC <> 0 THEN                         <<check for errors  >>
    BEGIN
     PRINT "FOPEN ERROR";
     CALL PRINTFILEINFO (PV'FNUM);
     CALL TERMINATE;
    END;

  CALL FFILEINFO (PV'FNUM,10,PV'FSIZE);   <<Get the file size >>
  PV'FSIZE    = PV'FSIZE - 1;             <<adjust by 1       >>
  PV'SEED     = RAND1;        <<Establish seed number>>
  PV'RAND'NO  = RAND(PV'SEED);<<Get a random number  >>
  PV'FRECORD  = PV'RAND'NO * PV'FSIZE;<< Map it to a >>
                              <<specific record in the file>>
  REPEAT                      <<Read backward to locate the >>
    CALL FREADDIR (PV'FNUM, HOLD.LDATA, -80, PV'FRECORD);
    IF CC = 0 THEN
....
...

Perhaps something similar can be used if you keep the employee names in a
flat file, or an image detail dataset and use the file's EOF along with the
random number to perform a directed read/get.  Selected entries are flagged
so that they would not be picked again....etc,

If you'd call the RAND1 intrinsic multiple times it is suggested that the
random number from the n'th call be used as the seed number to the n'th+1
call.

Regards

Paul H. Christidis


______________________________ Reply Separator _________________________________
Subject: Re: Random employee selection -Reply
Author:  Art Bahrs <[log in to unmask]> at CCGATE
Date:    10/21/97 03:19 PM


Hi All,
   Ok, seeing I get to visit this question on a regular basis with the National
Guard...

    They do a "percentage based random drug test" every so many months.   It
seems to be based on the last digit of the SSN...If they want 70% they just pick
seven of the 10 digits 0,1,2,3,4,5,6,7,8,9 and everyone who's SSN ends in that
number gets to be tested! Oh Joy of Joys hehehe :)

I think Steve is right about just using the RAND() function.... tho I think that
it can produce "reproducable and therefore predictable" results ??

Art "been a while since I had to write a random number generator" Bahrs

>>> Steve Dirickson b894 WestWin <[log in to unmask]> 10/21/97 11:35am
>>>
<<The original posting should probably have said that the selections
"could" change from year to year, as it is theoretically possible to
randomly select the same employees every year.  This is OK although we
need to make sure that the same employee is not selected more than once
in the same year.  I also have been told that there may be COBOL
INTRINSICS that could be used for this.  Is this a possible solution?>>


Again, a truly random selection not only allows a given entry to be
selected twice in a row, but must allow every entry to have the same
selection probability every time the process is run. This means, for
example, that a given employee could be selected five times in a row.
Selecting one employee each time from a list of ten gives odds of
100,000:1 against the five-in-a-row sequence. However, if the probability
is artificially forced to be zero, the system is not random. In fact, it
is explicitly non-random, and using it for something like drug-testing
selection would likely be the basis of a successful court challenge.

As for the method, I'm not a COBOL programmer, but every other language
I've used (C, FORTRAN, BASIC) had a function that returned a
pseudo-random sequence. There's also the 'RAND()' intrinsic in XL.PUB.SYS
(I think that's where it lives); it's documented in the "Compiler
Library/XL" manual (which is packed away at the moment-we're getting
ready to change buildings-so I can't give you a page reference).

Steve

ATOM RSS1 RSS2