Determined by a fair dice toss
I do mind. Iâm on Java 6. ;D
Why donât you update to Java 7?
I thinking of asking my dad to update my computer.
What does this have to do with Java 7?
oh you must be on a non-admin account. carry on
Or a gasp old Mac version!
Cheers!
A basic summary of java.util.Random (and everything based on it is) is meh:
-
Random is thread safe. Iâd guess that this was chosen to make it general purpose and so people could use it without any PRNG knowledge. Bad choice IMHO. You never ever want to call the same generator in more that one thread. It makes your code non-deterministic. While that might sound good for random numbersâŚthatâs an illusion as it doesnât improve the quality, it just makes your code hard (or near impossible) to debug. Secondly it means youâre hitting the same memory if two concurrent threads are generating at the same time which leads to cache thrashing. Bad bad. For ThreadLocalRandom this obviously isnât an issue. Never use the same generator on more than one thread. Because of this you never what to use Math.random(), unless single-threaded. (That call really shouldnât exist IHMO).
-
Neither the method nor the chosen constants were not âstate-of-the-artâ when it was first written. Far from in fact. My educated guess is it was thrown together in a rush pulling stuff from the then most recent version of Knuthâs Art of⌠book. Having said that, it was (and to an extent still is) a popular choice and at the time was a reasonable-ish one. While for gaming purposes this isnât a big deal, but itâs kinda desirable to get the most bang for a given cost.
-
They use a rejection method to get integer results. This involves a modulo (slowâŚless so today, but still slow). The purpose of the rejection method is to improve uniformity of the result (equal probability of all values in the range) when performing the mod (so only for non-power-of-two ânâ). The problems here are that, first mod-power-of-two LCG are poorish quality generators (again, more than sufficient for gaming purposes) and doing a rejection method with this rather silly. Secondly mod gives higher importance to low-bits, which for mod-power-of-two LCGs are the least random (you want to use high bits). But the biggest issue isâŚyou donât need to use a modulo anyway. Using fixed point (or floating point like some of the examples above) multiplication avoids the problem and itâs crazy faster.
-
The methods that returned floats was broken (improperly biased) for many versions
So, individually each of these is âmehâ, but combined in a big palmslap.
OP: I should have mentioned, I threw this together for simulating die rolls: http://www.java-gaming.org/topics/dice-roller/26974/view.html.
Thank you for the detailed explanation. Now I know better why you said, itâs bad. Particularly (3) doesnât sound like there were experts at work, indeed.
Everything Roquen says is spot on, but Iâd add that j.u.Random is still good enough for your average RPG dice roller. Just donât use the static methods, and never use it (or any other PRNG) where real money or sensitive info is on the line.