On 2026-10-24 05:14, Jörg Yadgar Bleimann <yazd…@gmx.de> wrote:
> Habe erst kürzlich angefangen, das Perl-Tutorial von Eike Grote (Version
> 2.05) durchzuarbeiten und bin jetzt gerade bei den Zufallszahlen (S.
> 29), wo beschrieben wird, wie rand() und srand() zusammenwirken... ich
> habe das Beispielprogramm abgetippt und gestartet - und wundere mich,
> dass nicht nur die dritte Variante der Ausgabeschleife (srand() ohne
> Parameter), sondern auch die erste bei jedem Programmlauf neue Werte
> erzeugt (natürlich aber nicht die zweite, wo ein fester Parameter für
> srand() verwendet wird). Wird ohne srand() bei Verwendung von rand()
> srand() implizit verwendet?
Ja. Aus »perldoc -f rand«:
| rand EXPR
| rand Returns a random fractional number greater than or equal to 0
| and less than the value of EXPR. (EXPR should be positive.) If
| EXPR is omitted, the value 1 is used.
| [...]
| Automatically calls "srand" unless "srand" has already been
| called. See also "srand".
und »perldoc -f srand«:
| If "srand" is not called explicitly, it is called implicitly
| without a parameter at the first use of the "rand" operator.
hjp