> On Monday 17 June 2002 20:46, you wrote: > > Hello guys! > > > > Can someone explain me how to use the random and srandom > > (or their half-equals rand() and srand(),) in linux ? because the > > man page doesn't really help much, and my programming books > > have nothing about it... > > > > Thanks in advance, > > Eliran > >From NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (www.nr.com), > chptr 7: > "Now our first, and perhaps most important, lesson in this chapter is: be > very, very suspicious of a system-supplied rand() that resembles the one just > described. If all scientific papers whose results are in doubt because of bad > rand()s were to disappear from library shelves, there would be a gap on each > shelf about as big as your fist..." > Read the whole chapter for more.. > (http://www.ulib.org/webRoot/Books/Numerical_Recipes/bookcpdf/c7-0.pdf though > ../c7-8.pdf) >
The reference you mentioned (Numerical_Recipes) already been referred to: Quoting rand (3): NOTES The versions of rand() and srand() in the Linux C Library use the same random number generator as random() and sran dom(), so the lower-order bits should be as random as the higher-order bits. However, on older rand() implementa tions, the lower-order bits are much less random than the higher-order bits. In Numerical Recipes in C: The Art of Scientific Computing (William H. Press, Brian P. Flannery, Saul A. Teukolsky, William T. Vetterling; New York: Cambridge University Press, 1992 (2nd ed., p. 277)), the following comments are made: "If you want to generate a random integer between 1 and 10, you should always do it by using high-order bits, as in j=1+(int) (10.0*rand()/(RAND_MAX+1.0)); and never by anything resembling j=1+(rand() % 10); (which uses lower-order bits)." Random-number generation is a complex topic. The Numeri_ cal Recipes in C book (see reference above) provides an excellent discussion of practical random-number generation issues in Chapter 7 (Random Numbers). For a more theoretical discussion which also covers many practical issues in depth, please see Chapter 3 (Random Numbers) in Donald E. Knuth's The Art of Computer Program_ ming, volume 2 (Seminumerical Algorithms), 2nd ed.; Read ing, Massachusetts: Addison-Wesley Publishing Company, 1981. CONFORMING TO SVID 3, BSD 4.3, ISO 9899 -- Shaul Karl, [EMAIL PROTECTED] e t ================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]