1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\" Modified Mon Mar 29 22:48:44 1993, David Metcalfe
28 .\" Modified Wed Apr 28 01:35:00 1993, Lars Wirzenius
29 .\" Modified Sat Jul 24 18:39:41 1993, Rik Faith (faith@cs.unc.edu)
30 .\" Modified Thu May 18 10:10:13 1995, Rik Faith (faith@cs.unc.edu) to add
31 .\" better discussion of problems with rand on other systems.
32 .\" (Thanks to Esa Hyyti{ (ehyytia@snakemail.hut.fi).)
33 .\" Translated to German Sat May 18 19:00:00 1996 by Patrick Rother <krd@gulu.net>
35 .TH RAND 3 "18. Mai 1996" "GNU" "Bibliotheksfunktionen"
37 rand, srand \- Zufallszahlengenerator
40 .B #include <stdlib.h>
44 .BI "void srand(unsigned int " seed );
49 liefert eine Pseudozufalls-Ganzzahl (integer) zwischen 0 und
54 setzt ihr Argument als Ursprung für eine neue Reihe von
55 Pseudozufalls-Ganzzahlen ein, welche von
58 Diese Sequenzen sind durch Aufruf von
60 mit dem selben Ursprungswert wiederholbar.
62 Wenn kein Ursprungswert angegeben wird, wird 1 als Ursprungswert für
68 liefert einen Wert zwischen 0 und
72 liefert keinen Wert zurück.
75 .BR rand() " und " srand()
76 in der Linux C-Bibliothek benutzen den selben Zufallszahlengenerator wie
77 .BR random() " und " srandom() ,
78 d.h. niederwertige Bits sind genauso zufällig wie höherwertige Bits.
79 Bei älteren Implementationen von
81 sind niederwertige Bits jedoch viel weniger zufällig als höherwertige Bits.
84 .I Numerical Recipes in C: The Art of Scientific Computing
85 (William H. Press, Brian P. Flannery, Saul A. Teukolsky, William
86 T. Vetterling; New York: Cambridge University Press, 1990 (1st ed,
87 p. 207)), finden sich die folgenden Kommentare:
89 "Wenn Sie Zufalls-Ganzzahlen zwischen 1 und 10 erzeugen möchten, sollten Sie
90 dies immer wie folgt tun:
93 j=1+(int) (10.0*rand()/(RAND_MAX+1.0));
96 und niemals auf folgene oder ähnliche Weise:
99 j=1+((int) (1000000.0*rand()) % 10);
102 (wodurch niederwertige Bits benutzt würden)."
105 Zufallszahlenerzeugung ist ein kompliziertes Thema. Das Buch
106 .I Numerical Recipes in C
108 liefert eine exzellente Diskussion über praktische Zufallszahlenerzeugung
109 in Kapitel 7 (Zufallszahlen).
111 Für eine mehr theoretische Diskussion, die auch viele praktische Aspekte
112 behandelt, sehen Sie bitte Kapitel 3 (Zufallszahlen) in Donald E. Knuths
113 .IR "The Art of Computer Programming" ,
114 volume 2 (Seminumerical Algorithms), 2nd ed.; Reading, Massachusetts:
115 Addison-Wesley Publishing Company, 1981.
117 SVID 3, BSD 4.3, ISO 9899