According to Jesper Lund:
PROCEDURE Randomize; BEGIN SRand(GetPID); RandSeed:=Rand END;
I don't see how this should emulate the Randomize procedure in Borland Pascal. According the info docs for my C library, getpid returns the unique process number for the program running on the system. If you call getpid twice in the same program, you get the same integer. Why not compute a seed from the system time (somehow), as Borland Pascal does?
If the sysetm time is always available, I agree.
OTOH, `Randomize' should never be used twice in the same program! I know someone who tried to get "even more random" numbers by calling `Randomize' before each sequence of calls to `Random', but the calculations in between were so fast that the time did not change between two `Randomize's. As a result, the random numbers were the same in all sequences - with Borland Pascal.
That is, if we need a Randomize procedure at all? My C library (DJGPP) doesn't have such a beast. Ok, there is Borland compatibility ....
I use random numbers a great deal in my work (statistical simulations), and in most cases (if not all) I specify the seed myself, since this is the only way of gettting reproducible results. [...]
For scientific application I agree. For games and such, that little bit of "true random" is a must.
The following piece of code represents a widely used procedure for generating uniform random numbers (reals between 0.0 and 1.0), but it could easily be changed to generating integers between 0 and 2^31-1 (just modify the last line in RanUni).
If the quality of these random numbers can compete with those produced by the GNU or BSD C library, and if there are no problems with copyright, I would be happy to incorporate this code into GPC's run time library and to implement BP's `Randomize' and `Random' for GPC on top of that (perhaps with Frank's unit as a replacement for those who specify `--borland-pascal' for 100% compatibility;-).
Greetings,
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [971005] maintainer GNU Pascal [971001] - http://home.pages.de/~gnu-pascal/ [971005]
If the quality of these random numbers can compete with those produced by the GNU or BSD C library, and if there are no problems with copyright, I would be happy to incorporate this code into GPC's run time library and to implement BP's `Randomize' and `Random' for GPC on top of that (perhaps with Frank's unit as a replacement for those who specify `--borland-pascal' for 100% compatibility;-).
Is there a well-defined standard for the ANSI, GNU or BSD `rand' function? If so, where can I find it? The only thing I have is the source code for rand in my DJGPP C library.
Regards,
Jesper Lund