[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Q: confusion about random generators
From: |
Myriam Abramson |
Subject: |
Re: Q: confusion about random generators |
Date: |
31 Jul 2001 11:42:48 -0400 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.3 |
> Isis GIRALDO <address@hidden> scribbled furiously:
<snip>
> I'm trying now to use the the java Random class, but as java doesn't
> allow global variables I'm struggling to find out how to use the same
> random generator in all my classes and give the seed as an argument at
> running the program.
<snap>
There is a way to have global-like variables in Java and I also use
that to set a random number generator.
public final class Utils {
static Random rand = new Random();
}
Thereafter, you can just say Utils.rand.nextInt() to draw random
integers from the same random generator from all your classes.
You can set the seed as well by setting Utils.rand = new Random(seed)
from anywhere.
Hope that helps.
--
myriam
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.