Conditionals are always tricky. Does hotspot convert into a branch or not...if a branch on average will the prediction be correct. A correctly predicted branch is as close to free as possible...mispredicted can get quite expensive. Hotspot has change alot, but branchless versions are still interesting. As an example HotSpot engineers are currently wondering what to do about Math.max & Math.min...both of which are intrinsic, but they way they are lowering (to a conditional move) can have drastically negative impact on performance. (The start of the conversion is here:

http://comments.gmane.org/gmane.comp.java.openjdk.hotspot.compiler.devel/13893, but there's quite a few comments since) A specific comment in that thread, no showing here is "Bit twiddling vs cmov is hard to guess at. With register renaming (and register files seem to be growing) and more exec units it's possible that bit twiddling can end up faster, but sure, this is not a rule." For min/max is dep-chain length is four and it needs one temp register..not heavy weight, so it's going to depend on what surround code is doing.

But in general, just use one that works. You only need to think about the choice at some "spots" that are inside something you need to juice cycles out of and you can't think of any other options.

int result = seed % n; return result < 0 ? -result : result; |

can be replaced by

and you can kill the division by treating the result as fixed-point (

https://github.com/roquendm/JGO-Grabbag/blob/master/src/roquen/math/rng/PRNG.java)