× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: Random Number in PRG: example
  • From: "DeLong, Eric" <EDeLong@xxxxxxxxxxxxxxx>
  • Date: Wed, 25 Apr 2001 11:14:34 -0500

Hi Jim, 

This idea occurred to me too, but again the problem is predictable usage.
Under certain conditions, its possible for the same seed values to be
recurring. That is, if:
1) the program always retrieves the same number of "random" values (lets say
100),
2) since the returned values are not truly "random", if you ever supply the
same seed again, you will loop through the same sequence of values, and
again store the last returned value, which itself duplicates a prior
sequence of "random" numbers. 

It's sort of a feedback loop, and all it takes is one recurrence of the seed
to stick you in a loop. Now, is this really going to happen in the real
world? Who knows, but I wouldn't want to make any bets on it. Personally,
I'd rather look at some non-related value to act as seed. Scott's job
number/microsecond combo are pretty random, and should generally produce
good seed values....

With all that said, I haven't had any need for random numbers in any program
for years. This is all very interesting to me, but I can't say that this is
really that critical........

Eric DeLong

-----Original Message-----
From: Jim Langston [mailto:jimlangston@conexfreight.com]
Sent: Wednesday, April 25, 2001 10:18 AM
To: RPG400-L@midrange.com
Subject: Re: Random Number in PRG: example


After you run this program, take the last random number generated and stick
it somewhere.  A dataqueue, a file somewhere, wherever.  When you run this 
program again, read the last random number and use it for the seed.

Regards,

Jim Langston

Me transmitte sursum, Caledoni!

"DeLong, Eric" wrote:
> 
> True, I added the time seed shortly after posting the example, and I too
> realized that Hans' example was repeating sequences.  It also occurs to me
> that seeding by TIME (6.0) could be a bad idea is the program runs at the
> same time every night (scheduled job). It's not hard to imagine the same
> seed value being used repeatedly...... perhaps something more random like
> milliseconds....
> 
> Eric DeLong
> 
> -----Original Message-----
> From: Paul Cunnane [mailto:paul@cunnane.net]
> Sent: Wednesday, April 25, 2001 7:57 AM
> To: RPG400-L@midrange.com
> Subject: Re: Random Number in PRG: example
> 
> Caveat: every time you run this, you will get the same sequence of
`random'
> numbers.  To get more truly pseudo-random numbers, seed the generator with
> (say) the result of the TIME opcode.
> 
> I also tried this code without seeding the generator (commented out the
> callp srand line), and got different, random-looking number sequences.
> Maybe this is the best approach?
> 
> --
> Paul
> 
> ----- Original Message -----
> From: "DeLong, Eric" <EDeLong@Sallybeauty.com>
> To: <RPG400-L@midrange.com>
> Sent: Tuesday, April 24, 2001 9:01 PM
> Subject: RE: Random Number in PRG: example
> 
> > Ugh! That might work ok, but it's a bit dated..... If you're using
RPGIV,
> > give this a spin.
> >
> > ---------------------------------------------------------------
> > H dftactgrp(*no) bnddir('QC2LE')
> > D rand            pr            10i 0 extproc('rand')
> > D srand           pr                  extproc('srand')
> > D                               10i 0 value
> > D num             s             10i 0
> > D i               s             10i 0
> > C                   callp     srand(123)
> > C                   for       i = 1 to 10
> > C                   eval      num = rand
> > C     num           dsply
> > C                   endfor
> > C                   eval      *inlr = *on
> > ----------------------------------------------------------------
> >
> >
> > This was right out of the archives (thanks Hans). SRAND seeds the random
> > generator, and RAND returns the random numbers. MUCH  simpler than the
> > RPGIII code you found.
> >
> > hth,
> > Eric DeLong
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator:
david@midrange.com
+---

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.