4 ms·
Name another language where random() is deterministic. Ask yourself why that is. As to bugs. Let's start with the famous one: http://alife.co.uk/nonrandom/
by SeanLuke 3y ago
Name another language where random() is deterministic. Ask yourself why that is.
As to bugs. Let's start with the famous one:
http://alife.co.uk/nonrandom/ http://alife.co.uk/nonrandom/
This is due to boneheaded mistakes in Sun's choice of constants for its LCG and errors in its bit-handling. These are massive mistakes, which it can no longer fix.
Next, there's an outstanding bug in nextBytes(), which generates ints and then cuts them into bytes (a big no-no for this particular LCG).
Some unfortunate omissions: nextChar(), nextShort(), nextByte() are missing, and there is no save-state procedure. There is no nextDouble() method that is inclusive for one or exclusive for zero.
There was a notorious bug in nextGaussian() which would take the log of 0 and then divide it by 0, but that has long been fixed. :-) [And some other bugs which were fixed early on despite Sun's claim that it couldn't fix bugs due to its stupid nondeterminism promise. For an RNG!]
- _a_a_a_ 3y ago> Name another language where random() is deterministic pretty well all of them, surely? eg. https://learn.microsoft.com/en-us/sql/t-sql/functions/rand-transact-sql?view=sql-server-ver16 https://learn.microsoft.com/en-us/sql/t-sql/functions/rand-t... "For a specified seed value, the result returned is always the same." Pretty well every language I'm aware of does it this way. Are we even talking about the same thing? As for the others you point out, I'm afraid I can't speak for that. I'll just have to accept what you say.
- adgjlsfhk1 3y agoJulia, for example promises that seeded random numbers will only be the same within the minor version and there's a 3rd party package if you need reproducible random numbers. Guaranteeing cross version random number compatibility comes at a pretty major cost for performance (as new better algorithms are discovered) and removes your ability to bugfix the random number generator.
- ygra 3y agoAny PRNG will return the same sequence when starting with the same seed. That's basically the point of it and it's quite a useful and important property, e.g. for simulations where you then just have to document your chosen PRNG and the seed for others to replicate your results instead of also shipping gibibytes of random numbers. And since the exact algorithm has been documented for java.util.Random you can't just change it. That being said, .NET had a similar problem, with System.Random having some drawbacks and bugs over the years. They chose to keep the algorithm the same when a seed is used (again, it's an important property you don't just break), but otherwise switch to something completely different. It gets more complicated even, as you can derive from Random there and some of those changes may be observable, so they also check for that: https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/Random.cs,bb77e610694e64ca https://source.dot.net/#System.Private.CoreLib/src/libraries...
- cumstain 3y agoDeterministic random number generation, where the same seed produces the same sequence of random numbers, can be achieved in various programming languages through different methods or libraries. Here are some programming languages and methods that allow for deterministic random number generation: 1. Python: The `random` module can be seeded to produce deterministic random sequences. 2. Java: Java's `Random` class can be seeded to produce deterministic random sequences. 3. C++: The C++ Standard Library provides functions like `srand` and `rand` that can be used for deterministic random number generation when seeded. 4. C#: C# offers the `System.Random` class, which can be seeded for deterministic randomness. 5. JavaScript: In browsers and Node.js, the `Math.random` function can be overridden to make it deterministic. 6. MATLAB: MATLAB's `rand` function can be made deterministic by setting the seed with `rng`. 7. Ruby: Ruby's `Kernel.rand` method can be seeded for deterministic random numbers. 8. Julia: Julia provides a `Random.seed!` function to set the seed for deterministic randomness. 9. R: R has functions like `set.seed` to control the randomness and make it deterministic. 10. Swift: In Swift, you can use the `arc4random_uniform` function with a fixed seed for deterministic random numbers. These are just a few examples, and many other programming languages and libraries offer similar functionality for deterministic random number generation when a specific seed value is used.
- SeanLuke 3y ago[Sigh] Sounds are misunderstanding what I meant by determinism, my apologies. Of course a given instance of an RNG will generate the same sequence given the same seed. That's not the issue. The issue is Java historically has guaranteed that, for all future versions and implementations of Java, the RNG will produce the exact same sequence given the same seed. It is deterministic across language versions and implementations. This is extremely unusual for a programming language, and a very bad idea. Java's RNG has grievous errors: but these bugs cannot be fixed because it would change the sequence! Its bugs are fixed in stone.