|
Hello Paul, You wrote: >Um. CEERAN0 updates the seed, in order to _give_ you a pseudorandom >sequence. If you reset the seed to zero each time, you are tinkering with >the pseudorandom algorithm, and I would expect the results to be less >"random" than using the returned seed value. I know CEERAN0 updates the seed. That's why I suggested changing it on each call. All that does is start the sequence again and will quite likely result in numbers that are badly random, however Mike didn't seem to actually want random numbers, only different numbers. He is going to have to experiment to find a solution that fits his requirements. Note the use of 'may' in my suggestion ... read Knuth's quote again. Another possibility is to generate a sequence of pseudo-random numbers from a seed of zero and once finished with that sequence reset the seed to zero and do it again. Since the GMT is likely to be different the sequence will be different (although the same numbers could be generated). Since I don't know exactly what GMT means when used by the API I could be completely wrong but I'd guess that it means the time_t returned by the time() function which is the number of seconds since EPOCH (00:00:00 Jan 1st, 1970 -- the supposed birth of Eunuchs). Since that value is constantly incrementing the seed will never be the same. >Of course, I could be wrong (I believe this has happened at least twice :), >but my experiments with CEERAN0 shows that it gives a nicely uniform >frequency distribution. It does, but Mikes 'problem' was avoiding repeating sequences due to using the same seed which can't be done without changing the seed. Here is a trivial example program written in free-format RPG: #include <stdlib.h> #include <stdio.h> #include <lemath.h> int main(void) { int x=0,y=0; double f=0.0; printf("Random numbers with zero seed using CEERAN0\n"); for (x = 1; x <= 10; x++) { y=0; printf("seed=%d, ", y); CEERAN0( &y, &f, NULL); printf("iteration %d, rand=%f, seed=%d\n", x, f, y); } } The program generated the following output: Random numbers with zero seed using CEERAN0 seed=0, iteration 1, rand=0.939558, seed=2017684432 seed=0, iteration 2, rand=0.267679, seed=574836272 seed=0, iteration 3, rand=0.153093, seed=328765360 seed=0, iteration 4, rand=0.923922, seed=1984107216 seed=0, iteration 5, rand=0.252043, seed=541259056 seed=0, iteration 6, rand=0.137458, seed=295188160 seed=0, iteration 7, rand=0.908286, seed=1950530016 seed=0, iteration 8, rand=0.236408, seed=507681840 seed=0, iteration 9, rand=0.564529, seed=1212317328 seed=0, iteration 10, rand=0.892651, seed=1916952816 Regards, Simon Coulter. «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«» «» FlyByNight Software AS/400 Technical Specialists «» «» Eclipse the competition - run your business on an IBM AS/400. «» «» «» «» Phone: +61 3 9419 0175 Mobile: +61 0411 091 400 «» «» Fax: +61 3 9419 0175 mailto: shc@flybynight.com.au «» «» «» «» Windoze should not be open at Warp speed. «» «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«» +--- | 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 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.