Mainframe too fast for Rexx?



IBM's Command List programming language & Restructured Extended Executor

Mainframe too fast for Rexx?

Postby NicC » Sun Jun 09, 2013 3:35 pm

Here is an interesting one..

I have an exec that generates random numbers (for the lottery). It has an option to get numbers for up to 4 lines (5 main numbers and 2 lucky star numbers). When I step through this it all works fine - each set of numbers is different - but when I take the trace off all the lines are identical. I was pulling my hair (what is left of it) out trying to determine why. Eventually I just added a "Pull ." after each line and I started to get unique lines. My conclusion is taht the CPU is too fast for the random function but could anyone elucidate? My first call to the Random function specifies a seed of TIME(S) just so that I do not get the same numbers each week. Subsequent calls do not use a seed.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Mainframe too fast for Rexx?

Postby BillyBoyo » Sun Jun 09, 2013 3:47 pm

The seed can be anything. It is not related to TIME, it is just that TIME is commonly used as a way to get a variable value to use as a starting point. The "random" number is a pseudo-random number, It is a sequence of numbers from the starting point, which is always repeatable given the same starting-point. The numbers returned exhibit a "random distribution".

How about showing the code?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Mainframe too fast for Rexx?

Postby steve-myers » Sun Jun 09, 2013 3:52 pm

Are you getting a new "seed" for every RANDOM call? If the computer is fast enough, you'll probably get the same seed every time.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Mainframe too fast for Rexx?

Postby enrico-sorichetti » Sun Jun 09, 2013 6:17 pm

Hello Nic,

what happened when You tried without the initial SEED,
REXX already uses some kind of unpredictable SEED when none is specified,

I only used it to get repeatable sequences for testing,
when going live I would simply issue the initial call without the SEED.

cheers
E
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3003
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Mainframe too fast for Rexx?

Postby NicC » Sun Jun 09, 2013 6:26 pm

I know the seed can be any number (up to 100000 I think, without looking at the manual). As Billy said I used TIME(S) just to be sure, to be sure (as I am in Dublin). As this is set for the first number for each iteration I should get a differeing result each time when running on the same day. I am not getting different number within the same execution because it just executes too fast.
Re Steve's question, subsequent calls to Random() are without specifiying a seed. I am doing a minimum of 7 calls in each iteration with only the first having the seed specified as mentioned.

Sorry, cannot give the code because it is on the work mainframe and I am at "home". However, the core of the code was lifted from the same exec that runs just dandy on my home laptop. The only differences being that at home I use SPF/PC panels to communicate with the user (get number of lines to generate and display the results).

Just added this last bit for Enrico:
It does not matter what the seed is - I get my 7 numbers and on the second iteration I get the same numbers UNLESS I slow the execution down.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Mainframe too fast for Rexx?

Postby enrico-sorichetti » Sun Jun 09, 2013 6:45 pm

I would try to use the microseconds part of time("E")

on my IMAC I get
----- REXXCPS 2.1 -- Measuring REXX clauses/second -----
 REXX version is: REXX-ooRexx_4.2.0(MT) 6.04 27 Aug 2012
       System is: MACOSX
       Averaging: 100 measures of 100 iterations

Total (full DO): 0.01612036 secs (average of 100 measures of 100 iterations)
Time for one iteration (1000 clauses) was: 0.0001612036 seconds

     Performance: 6203335 REXX clauses per second

[enrico@enrico-imac bin]$

note the 6 million clauses per second

and a simple

do 10
say time("e")
end

returned
0
0.000043
0.000071
0.000099
0.000123
0.000152
0.000179
0.000204
0.000230
0.000255

just discard the first call to time("e")
and it should be enough

I tested again with

call time("e")
do 10
    seed = right(time("e"), 6)
    say seed right(random(1,999999,seed), 6)
end

to get
000021 888288
000073  30922
000102 200763
000131 256635
000159 133970
000187  55595
000213 236208
000241 469119
000266 504559
000294 605040


I posted the REXXCPS results to find out if under TSO rexx could be deliver more

since I am pretty curious could You post the rexxcps results for TSO

Cheers
E
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3003
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Mainframe too fast for Rexx?

Postby enrico-sorichetti » Sun Jun 09, 2013 6:59 pm

hit enter too fast on the previous one

here is a different experiment

do 10
    say right(random(1,999999), 6)
end

result

 42303
862079
383411
456323
212458
109192
781261
507846
332719
819767


and running the above for 10000 times ( do 10000 ) I got 63 duplicates.
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3003
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Mainframe too fast for Rexx?

Postby BillyBoyo » Sun Jun 09, 2013 7:33 pm

With TIME(S) as the seed, it is not going to take too zippy a CPU to get the same TIME(S) for five iterations.

I only ever specify one seed for use of RANDOM (whatever language) and roll with that.

If you use TIME(S), if you happen to, to the second, run it at the same time as one you have done previously, you will get the same numbers. Not so difficult to do. We used to "draw" our numbers at 17:00 on a Friday.

Notes:

To obtain a predictable sequence of quasi-random numbers, use RANDOM a number of times, but specify a seed only the first time. For example, to simulate 40 throws of a 6-sided, unbiased die:

sequence = RANDOM(1,6,12345) /* any number would */
/* do for a seed */
do 39
sequence = sequence RANDOM(1,6)
end
say sequence

The numbers are generated mathematically, using the initial seed, so that as far as possible they appear to be random. Running the program again produces the same sequence; using a different initial seed almost certainly produces a different sequence. If you do not supply a seed, the first time RANDOM is called, the microsecond field of the time-of-day clock is used as the seed; and hence your program almost always gives different results each time it is run.
The random number generator is global for an entire program; the current seed is not saved across internal routine calls.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Mainframe too fast for Rexx?

Postby NicC » Mon Jun 10, 2013 8:01 pm

Well, thanks to this discussion, I have put an initial Random call with a seed before my main loop. It's sole action is to set the seed 'randomly' i.e. by seconds since midnight and I ignore the returned value - much as I hate to do so!

Anyway - the main point of this topic was really to provide 'yet another thing to be wary of when your rexx program seems not to work'.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post