[concurrency-interest] ThreadLocalRandom initial seed

David Holmes davidcholmes at aapt.net.au
Fri Jun 3 07:38:34 EDT 2011


Thanks for correcxting me on that. This sure is confusing. It would seem
that  6955840 although trying to allow setSeed to be called from the random
constructor was completely pointless because Random stopped calling the
setSeed method.

I hope Martin is watching and can give some input here. It certainly seems
that we never properly initialize a ThreadLocalRandom!

David
  -----Original Message-----
  From: concurrency-interest-bounces at cs.oswego.edu
[mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Mark
Thornton
  Sent: Friday, 3 June 2011 6:58 PM
  To: concurrency-interest at cs.oswego.edu
  Subject: Re: [concurrency-interest] ThreadLocalRandom initial seed


  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/40f83f1a/attachment.html>


More information about the Concurrency-interest mailing list