| Hauptindex | Abschnitt 3 | English | 日本語 | Optionen |
#include <stdlib.h>int rand(void);
void srand(unsigned int seed);
Die Funktion srand() setzt ihr Argument als Ursprung für eine neue Reihe von Pseudozufalls-Ganzzahlen ein, welche von rand() geliefert werden. Diese Sequenzen sind durch Aufruf von srand() mit dem selben Ursprungswert wiederholbar.
Wenn kein Ursprungswert angegeben wird, wird 1 als Ursprungswert für rand() angenommen.
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, 1990 (1st ed, p. 207)), finden sich die folgenden Kommentare:
"Wenn Sie Zufalls-Ganzzahlen zwischen 1 und 10 erzeugen möchten, sollten Sie dies immer wie folgt tun:und niemals auf folgene oder ähnliche Weise:j=1+(int) (10.0*rand()/(RAND_MAX+1.0));
(wodurch niederwerte Bits benutzt würden)."j=1+((int) (1000000.0*rand()) % 10);
Zufallszahlenerzeugung ist ein kompliziertes Thema. Das Buch Numerical Recipes in C (siehe oben) liefert eine exzellente Diskussion über praktische Zufallszahlenerzeugung in Kapitel 7 (Zufallszahlen).
Für eine mehr theoretische Diskussion, die auch viele praktische Aspekte behandelt, sehen Sie bitte Kapitel 3 (Zufallszahlen) in Donald E. Knuths The Art of Computer Programming, volume 2 (Seminumerical Algorithms), 2nd ed.; Reading, Massachusetts: Addison-Wesley Publishing Company, 1981.
| 18. Mai 1996 | RAND (3) | GNU |
| Hauptindex | Abschnitt 3 | English | 日本語 | Optionen |
Bitte richten Sie Ihre Kommentare zu diesem Handbuch Seite Service, Ben Bullock. Privacy policy.
| “ | Our grievance is not just against Unix itself, but against the cult of Unix zealots who defend and nurture it. They take the heat, disease, and pestilence as givens, and, as ancient shamans did, display their wounds, some self-inflicted, as proof of their power and wizardry. We aim, through bluntness and humor, to show them that they pray to a tin god, and that science, not religion, is the path to useful and friendly technology. | ” |
| — The Unix Haters' handbook | ||