Hacker News new | past | comments | ask | show | jobs | submit login

Only if you started programming in Go. I've never in my life heard of another project that by default seeds with 0. That's insane.

EDIT: Okay, C and a bunch of other languages I don't use. Keep the roasts coming, guys. :D




You've never heard of the C programming language?


This was actually one of the tripups for me when I learned C originally to do OpenGL.

POSIX (or at least ISO C) defines rand as being seeded with 0 by default.


For anyone currently having a blast with ChatGPT/copilot, these are the sorts of unexpected behaviors you need to keep in mind when using it.

Stay safe everyone.


If you know how PRNGs work and it comes back pre-seeded, that's some magic that you may not be expecting

But of course, rather than make people study up, let's just dumb shit down


How old is your life?


matlab had a constant random seed around 2005, no idea whether they've changed it.


Every single BASIC variant I used in the 80s/90s right up to and including QBasic?


I'm quite sure I encountered this in VB.NET like 15 years ago or so.


I thought C did that?


Why is that insane?


Because almost everyone who asks for a random number expects a random number. Reusing a predictable seed _by default_ violates that totally reasonable expectation.

(BTW, I'm deliberately avoiding making any distinction between so-called "true random" and PRNG above, because the difference isn't actually meaningful here!)


I'd say the functions are commonly misnamed. The "secure random" function should be the "random" function, and the "PRNG based on a user-provided seed" should be called something else. Maybe "MonteCarlo", since that's one of the common uses.


I always thought it was perfectly intuitive that "random" wasn't really random on a computer.


Insane seems to me an obviously an intentionally dramatic word choice of GP, but it seems clear to me that the answer is “because subsequent runs the same program would produce the same sequence of random numbers.” This violates my personal intuition and assumptions about a programming language’s standard lib RNG behavior.

Not a Go programmer though but that was my understanding.


In the go std lib, there's an explicit difference between a cryptographically secure number generator and a pseudo random number generator. Their names alone reflects the difference very well: "crypt/rand" vs "math/rand" and the difference and properties of each is well documented.

Personally I've wrote a whole bunch of unit tests in the past that relies on that repeatability property "math/rand" has over "crypt/rand"


There's many uses for random numbers where cryptographic random is unnecessary, but where different runs of the program should use different pseudo random sequences.


Of course, but in those cases, you should make sure that your initial seeds are random. It seems like in the older Go cases, the initial seed was fixed. But, if you wanted random numbers, you could have used your own (truly random) seed.

I don't really see an issue with either default, so long as it's documented and you can use a fixed seed if you'd like. I personally like needing to set a random seed explicitly. But then again, I learned about using random number generators a long time ago when this was always required, so what I think is obvious is probably a surprise to many (as shown by this stdlib change).

The only downside about this new change was that in the old way, if you needed a cryptographically secure random number, you had to explicitly call those functions from the stdlib. The choice should have been deliberate, but people don't like to read documentation...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: