Random function not working
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Gearman Java |
Invalid
|
Medium
|
Eric Lambert |
Bug Description
This bug was originally filed by Norberto Leite in the gearman-ij project. Refilling it here ....
Hi there,
The GearmanClientImpl class has a bug on method getSessionForTask() when trying to collect a random value for the list of possible gearmanSession on the list. This line :
int s = (int) Math.round(
I have been testing this and it provides not "very random" at all.(most common value is 0!).
I recommend the use of :
Random rand = new Random(
int s = rand.nextInt(
There's a relative gain in performance and more decoupled organization of code without the need to use static functions:
(100000000 iterations loop)
Random -> 2287 mls
Math.random -> 6598 mls
Random with Constructor time -> 2320 mls
Cheers,
Norberto
this is a duplicate of #516194