Hallo!
Ich muss ein Programm schreiben, wo eine Zufallszahl mit Hilfe
der rand Funktion erzeugt werden muss. Dabei soll festgelegt
werden können, in welchem Bereich sich die Zufallszahl
befindet.
Hach ja, richtige Dokumentation ist was tolles. Aus der rand()-manpage:
The rand() function returns a pseudo-random integer between 0 and RAND_MAX.
[…]
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)."