Using system time directly to get random numbers
- by Richard Mar.
I had to return a random element from an array so I came up with this placeholder:
return codes[(int) (System.currentTimeMillis() % codes.length - 1)];
Now than I think of it, I'm tempted to use it in real code. The Random() seeder uses system time as seed in most languages anyway, so why not use that time directly? As a bonus, I'm free from the worry of non-random lower bits of many RNGs. It this hack coming back to bite me? (The language is Java if that's relevant.)