|
There are lots of things computers are good for. Being random isn't one of them. Since you use the same seed value all the time, you're going to end up with the same "random" number sequences. Most "random number generators" (including CEERAN0) generate what are called pseudo random numbers. The sequence is predictable using the same input values so you're actually seeing the expected behavior. A little bit of searching on Google turned this up which explains it better than I care to: http://triumvir.org/articles/rng/ Basically, what it gets down to is that you need to introduce some randomness (which is difficult since computers aren't very random) to generate better "random" numbers. Things like time and other stuff that changes frequently (network information, system activity levels, etc...) are generally used to seed random number generators to give better randomness. Feeding the random number back in as the seed value is an example of doing this. The article I reference above shows a better (as in more "random") way to do the same thing. You never said what the purpose of the random number was but if you just need a unique number, you can generate a UUID (Universally Unique ID -- these are supposed to be unique on all computers as opposed to a GUID [Globally Unique ID] which is only supposed to be unique on a given computer). Here's an example of doing that: D UUID_template DS D UtBytPrv 10u 0 Inz( %Size( UUID_template )) D UtBytAvl 10u 0 D 8a Inz( *Allx'00' ) D UUID 16a D GenUuid PR ExtProc('_GENUUID') D UUID_template * Value C Callp GenUuid( %Addr( UUID_template )) In this example, the result is stored in UUID which is character but since a UUID is a 128 bit integer you should be able to convert it to numeric with no problem. You could also convert it to a character representation of it's hex value (it will be 32 characters then) which is usually how you see them used since you probably will have unprintable characters in it's raw form as returned from the API. Matt -----Original Message----- From: Titus Kruse [mailto:t_kruse@xxxxxxxxx] Sent: Friday, April 30, 2004 8:18 AM To: RPG programming on the AS400 / iSeries Subject: Re: CEERAN0 not allways random? > > /Free > Seed = 0; > for c = 1 to 20000; > CEERAN0(Seed:Random:*OMIT); > Seed = Random * 1234 * c; > Number = %DecH(Random:30:29) * seed * 9999 ; > except; > endfor; Hmm, why do you take the random number for the new seed? Here my coding: > Seed = 0; > for c = 1 to 20000; > CEERAN0(Seed:Random:*OMIT); > Number = %Dec(Random) * 10 ** 16; > except; > endfor; _______________________________________________ This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
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.