z1 is never used.
Good point! chatGPT explained it thusly:
"The Box-Muller transform generates two normally distributed random numbers, z0 and z1, using the two uniformly distributed random numbers u1 and u2. However, only z0 is used in the provided function to create the random number within the given range. If you want to additionally supply z1 in the output, you can." It then provides the modified code.
Re:Random Numbers in Bash
by sureglymop on Monday March 27, 2023 @05:18PM
(#35332786)
AWK is amazing. I recommend reading "The AWK Programming Language", read it as a kid!
You can even do network programming with gawk: https://www.gnu.org/software/gawk/manual/html_node/TCP_002fI...
EDIT: Nope, there's definitely something wrong with this, possibly the rand() call(s)? Can anyone guess? (A real-world example of the perils of relying on chatGPT!) EDIT2: Figured it out. srand with no args seeds to the current second, making any run of this function within the same second produce the same result. Fixing this left as an exercise to the reader EDIT3: I fixed it by seeding it externally via $RANDOM.