[concurrency-interest] ThreadLocalRandom initial seed

Mark Thornton mthornton at optrak.com
Fri Jun 3 04:57:46 EDT 2011


On 03/06/11 07:43, David Holmes wrote:
> Aleksey,
>
> The problem is not the seed - all threads do get a distinct seed. The problem is that the first call to nextInt(n) is always returning zero - hence the sequence will always be the same. I haven't yet determined exactly what is going wrong.
>
> David
>
ThreadLocalRandom uses its own seed, not the seed of the super class.

     ThreadLocalRandom() {
         super();
         initialized = true;
     }

This uselessly initialises the parent seed via the default constructor but leaves the real seed at zero.


     ThreadLocalRandom() {
         super(0); // don't bother generating a seed we don't use
	setSeed(System.nanoTime());
         initialized = true;
     }

Mark Thornton




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20110603/ab22eb3d/attachment.html>


More information about the Concurrency-interest mailing list