News for hackers. Stuff that matters.
Re:Making Python Less Random by Neywiny on Thursday July 11, 2024 @09:28PM (#40942053)
Python randomness is something I've fought with for a few years. A while back (it's on my GitHub, I can find it if any replies care) I had an issue with something about distributed monte carlo sims all ending up with the same seed or something. More recently I've had an issue that I wanted a large number of random bytes but generated the same across multiple programs. Thinking about it now I could have used an LFSR or similar, but I just seeded the random module and it went fine.

Editing to add that another thing that trips me to every few years is that the hash function isn't repeatable between runs. Meaning if you run the program and record a hash of an object, then run it again, they'll be different. This is good for more secure maps and stuff but not good for thinking you can store them to a file and use them later.

Re:Making Python Less Random by kstrauser on Thursday July 11, 2024 @10:53PM (#40942423)
Re:Making Python Less Random by Neywiny on Friday July 12, 2024 @06:51AM (#40944369)
Correct. But it's not often mentioned until you go looking for it.
Re:Making Python Less Random by ajkjk on Friday July 12, 2024 @01:44PM (#40947747)
I think the right mental model of a hash is that it's a transient value. There's no setting in which it makes sense to store it unless you explicitly control the hash function. Even in languages where it is static over runs, it can change over language versions, which any saved data will (presumably) eventually hit.
Re:Making Python Less Random by Neywiny on Friday July 12, 2024 @03:53PM (#40948815)
Yes, while it's a great practice, it's just something that newbies of any programming like me at the time may run into. Often when being taught programming, hash functions are purely functions of input data. My point was that Python, for very valid and good reasons, does not do that.
Re:Making Python Less Random by ajkjk on Friday July 12, 2024 @05:29PM (#40949622)
Well they are pure functions of input data. It's just that which pure function they are should be treated as a random value that changes over runs / version numbers.