bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Apparent issue with srand() in gawk


From: Andreas Schwab
Subject: Re: Apparent issue with srand() in gawk
Date: Wed, 11 Jun 2025 13:07:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

On Jun 11 2025, Jim Mellander wrote:

> Interestingly, if I pull less than 4 bytes from /dev/urandom for a seed (e.g. 
> "od -t u4 -N 3 /dev/urandom") random numbers are generated as expected. Note 
> that all the seeds in the examples above are > 2^31, which could indicate a 
> signed vs unsigned int issue.

Values bigger than LONG_MAX overflow when converted from double to an
integer, resulting in undefined behaviour.  In your case the resulting
seed is always the same number, 2147483647 or 0x7fffffff.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]