Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 59215 invoked from network); 7 May 2003 13:58:24 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 7 May 2003 13:58:24 -0000 Received: (qmail 10575 invoked by uid 97); 7 May 2003 14:00:26 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 10568 invoked from network); 7 May 2003 14:00:26 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 7 May 2003 14:00:26 -0000 Received: (qmail 48827 invoked by uid 500); 7 May 2003 13:55:12 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 48785 invoked from network); 7 May 2003 13:55:11 -0000 Received: from umbongo.flamefew.net (64.253.103.114) by daedalus.apache.org with SMTP; 7 May 2003 13:55:11 -0000 Received: by umbongo.flamefew.net (Postfix on Linux (i386), from userid 500) id 437403A248B; Wed, 7 May 2003 09:55:12 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by umbongo.flamefew.net (Postfix on Linux (i386)) with ESMTP id 4213E296EB8 for ; Wed, 7 May 2003 09:55:12 -0400 (EDT) Date: Wed, 7 May 2003 09:55:12 -0400 (EDT) From: Henri Yandell X-X-Sender: To: Jakarta Commons Developers List Subject: Re: [lang] Support reseeding the RandomUtils random number generator In-Reply-To: <3EB8991B.7000006@steitz.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Sorry for being sleepy on this Phil. I had forgotten that I wrote RandomUtils. Problem with reseeding as I see it, RandomUtils initial aim was just to make Math.random() more useful. ie) to simulate Math.RANDOM being public. So if it can be reseeded, but Math.RANDOM cannot, then we need to redefine it's reason for being. Firstly, I think there's an important place for RandomUtils as is. ie) Linked to the same seed as Math.random() but providing the other methods. However there's also room for new improved Utils for Random objects such as your "b) add nextInt(min,max) (inclusive) and/or nextInt(IntRange r)". Reseeding of the static instance is nice, but not a huge biggy. However.... What I'm thinking is: RandomUtils, a series of static methods that take a Random object. So you would have: RandomUtils.nextInt(Random, min, max) RandomUtils.nextInt(Random) RandomUtils.chooseRandomly(Random, Collection, int, int) [ok. no clue what this would do] Then we would have JVMRandom, which extends Random. It would be an extension of java.util.Random which maps onto java.lang.Math.random(), in exactly the way that RandomUtils currently does. We would throw unsupported exceptions for setSeed(), nextGaussian() and nextBytes() [until we have implementations for the latter two] and make it available as RandomUtils.RANDOM or RandomUtils.JVM_RANDOM. We would optionally add RandomUtils.nextInt(min, max) which would call on through to RandomUtils.nextInt(JVM_RANDOM, min, max) as this would work as the user would expect. So the static instance would not be reseedable, as with the JVM it would effectively be immutable, but anyone who wants to use their own Random instance can quite happily use the methods in RandomUtils in the time-honoured XxxUtils.doThing(Xxx, others) way. How does that sound? It fixes the 'broken-ness' of RandomUtils' XxxUtils contract [we need to document the XxxUtils contract somewhere] and gives you a platform to start enhancing Random's methods in. You just don't get the ability to change the JVM_RANDOM's seed and have to carry your own new Random(). Hen On Tue, 6 May 2003, Phil Steitz wrote: > I can see two ways to do this: > > a) Leave the methods static,add a static field holding a > java.math.Random, which can be reseeded. "Scope" of seeding becomes > jvm/classloader. > > b) Add the Random as an instance variable and change the methods to be > instance methods. > > Pros of a): least change from current implementation, guarantees > "expected" random sequence behavior whether or not user ever reseeds. > Cons of a): usual objections to statics > > Pros of b): user has full control of his/her instance, no statics > Cons of b): if user creates a new instance each time, behavior will be > similar to using new Random() each time, which does not generate a good > random sequence. To get a good sequence, user needs to create an > instance and use that instance repeatedly. > > I have a patch that does a). Should I submit this or is b) a better > approach -- or is there another approach that is better than either a) > or b)? > > Phil > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-dev-help@jakarta.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org