-2

The question is pretty straightforward. What exactly happens when you use "srand" with no arguments? What is the expected behavior?

srand();
my $x1 = int(rand(65536)) % 65536;
my $x2 = int(rand(65536)) % 65536;
print "$x1\n";
print "$x2\n";
  • `man srand` sayeth `If no seed value is provided, the rand() function is automatically seeded with a value of 1.` (presumably applies to srand too) – Barry Carter Aug 14 '22 at 13:13
  • Possible duplicate of https://stackoverflow.com/questions/21273550/how-does-srand-relate-to-rand-function – JRFerguson Aug 14 '22 at 13:37
  • 1
    What do you think is happening? Note that you already have a number below 65536, so you don't need to take the modulus. – brian d foy Aug 14 '22 at 15:48

1 Answers1

2

According to the documentation:

When called with a parameter, "srand" uses that for the seed; otherwise it (semi-)randomly chooses a seed.

jhnc
  • 11,310
  • 1
  • 9
  • 26