× 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.



Hi Emily,

The ILE C function named rand() can be seeded by calling the srand() function. If you don't call srand(), it will automatically seed the random number generator with a value of 1. (Yes, that's right, it always picks 1 as the seed unless you tell it otherwise.)

Consider getting the current milliseconds from the clock (RPG example follows) and using that to seed the random number generator with a better value.

ms = %div(%subdt(%timestamp():*MS):1000);

Then take the value in 'ms' and pass it to srand() to set the seed.

Or, better yet, don't use the rand() function. The random number generator in C is notoriously bad... instead, consider using CEERAN0 or even better, the crypto API for the random number (the name escapes me at the moment, but if you can't figure it out, let me know and I'll look it up.)


Emily Smith wrote:

We have a program that uses 'rand' to generate random numbers. I
call this program requesting an eight byte number and receive a
number 81239122. I sign off, and a coworker signs onto my workstation
. . . etc . . .

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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.