-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Sean Luke wrote:
> The actual method is an internal, non-public method called
> setRandomNumberGenerator(int). Agreed, not a good name, nor is it
> public. I'll think about making it public; in the meantime, you
> *probably* can just make it public in Console.java. It'll be fine as
> long as it's not being called from within the simulation thread proper
> -- that is, from within a Steppable. If you call it from some GUI
> object or from your main() thread, you're probably fine.
Thanks! However, Console.startSimulation() looks like:
void startSimulation()
{
removeAllInspectors(true); // clear inspectors
setRandomNumberGenerator(randomSeed);
simulation.start();
...
So, when it calls startSimulation(), it will use randomSeed, which is
only set via Console(), Console.pressStop(), or at its declaration. So,
even if I call setRandomGenerator(int), it won't affect the value of
console.randomSeed. Hence, after you press the stop button, the _next_
simulation will use either the currentTimeMillis() or
currentTimeMillis() + 1.
So your recommendation would force me to call
setRandomNumberGenerator(myseed) in my over-ridden GUIState.start()
method. Plus, your recommendation doesn't help in programmatically
setting the incrementSeedOnPlay toggle.
What I want is to use the same seed for each subsequent run without
having to click on the Console tab, click inside the randomField, type
my number, hit enter, then hit play(). I.e. when I pressStop() I don't
want it to go back to the currentTimeMillis() value of randomSeed. I
want it to go back to the integer I chose. In other words, I need to
change the value of randomSeed. So, I'd be more interested in a public
method:
public class Console extends JFrame implements Controller {
...
public void setRandomSeed(int v) { randomSeed = v; }
...
That way when startSimulation() is called, it will re-set to my integer.
Right now, I simply create a mirror package (so I can gain access to
the protected variables and methods of sim.display.Console) called
sim.display and put my new sub-class in that mirror package. I.e.
- ------------------------------MyConsole.java--------------------------
package sim.display;
public class MyConsole extends sim.display.Console {
public MyConsole(int rngSeed, sim.display.GUIState s) {
super(s);
randomSeed = rngSeed;
randomField.setValue("" + randomSeed);
incrementSeedOnPlay.setSelected(false);
}
}
- ------------------------------------------------------------------------
This sort of thing is important for those of us who use live
visualization (via a GUIState) to verify and debug simulations. The
alternative is to engage in the 4 mouse clicks, number and enter
keystrokes everytime you want to re-run the simulation. (Or, you could
change and re-compile the mason console, thereby breaking your
simulation when you upgrade mason.... ugh... I'd rather have all my
relevant code under my source code repository. ... or you could restrict
yourself to off-line visualization and always verify/debug the
simulation using batch mode.)
- --
glen e. p. ropella, 971-219-3846, http://tempusdictum.com
If you haven't found something strange during the day, it hasn't been
much of a day. -- John A. Wheeler
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGxMkNZeB+vOTnLkoRAhreAJ4u2KSdHPwBxznTm/SQgqJJgjbYIACgsYQ1
1wEV6ws/8d4Z1P9wBoqgTdY=
=0yw4
-----END PGP SIGNATURE-----
|