5 ms·
I remember when I started programming this was one of the first quirks that really surprised me, I can just hear myself exclaiming "This is meant to be random!
by remus 4y ago
I remember when I started programming this was one of the first quirks that really surprised me, I can just hear myself exclaiming "This is meant to be random! Why do I keep getting the same result?!"
I feel strangely vindicated seeing this change.
- pkulak 4y agoOnly 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
- rileymat2 4y agoI thought C did that?
- philosopher1234 4y agoWhy is that insane?
- jeffparsons 4y agoBecause 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!)
- deleted 4y ago[deleted]
- sidlls 4y agoI always thought it was perfectly intuitive that "random" wasn't really random on a computer.
- SAI_Peregrinus 4y agoI'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.
- DiggyJohnson 4y agoInsane 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.
- mickael-kerjean 4y agoIn 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"
- JelteF 4y agoThere's many uses for random numbers where cryptographic random is unnecessary, but where different runs of the program should use different pseudo random sequences.
- mbreese 4y agoOf 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...
- deleted 4y ago[deleted]
- bch 4y agoHow old is your life?
- q845712 4y agomatlab had a constant random seed around 2005, no idea whether they've changed it.
- mik1998 4y agoYou've never heard of the C programming language?
- donatj 4y agoEvery single BASIC variant I used in the 80s/90s right up to and including QBasic?
- indrora 4y agoThis 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.
- TOMDM 4y agoFor 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.
- wsc981 4y agoI'm quite sure I encountered this in VB.NET like 15 years ago or so.
- pdntspa 4y agoIf 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