Re: Advice on managing random number generators across threads

2014-06-07 Thread Alexander Hudek
Keep in mind that there could be accuracy reasons why you might want to use multiple random number generators (aka multiple streams). See the section Single Versus Multiple Streams here: http://www.cse.msu.edu/~cse808/CSIM_Notes03/cse808/html_c/16random.htm Also, the built in java random

Re: Advice on managing random number generators across threads

2014-06-07 Thread Mars0i
On Saturday, June 7, 2014 7:09:53 PM UTC-5, Alexander Hudek wrote: Keep in mind that there could be accuracy reasons why you might want to use multiple random number generators (aka multiple streams). See the section Single Versus Multiple Streams here:

Advice on managing random number generators across threads

2014-06-06 Thread Mars0i
I'm writing an agent-based simulation framework, in which agents are Clojure records called Persons. There are 40-100 persons at present, but conceivably the number could go up to 1000. In each timestep, Persons' states are functionally updated by mapping update functions across the

Re: Advice on managing random number generators across threads

2014-06-06 Thread Mars0i
One more point: I would save the system-time-determined seed of the initial RNG to a file (i.e. the RNG used to generate seeds for each Person's RNG). I believe this will allow me to re-run a simulation with identical results, by seeding the initial RNG with the seed saved from the previous

Re: Advice on managing random number generators across threads

2014-06-06 Thread Gunnar Völkel
In Java 7 you would use ThreadLocalRandom you said in another thread. Well, in Java 6 you already have ThreadLocal [1] and thus you are able to build a thread local Random yourself to keep Java 6 as minimum requirement. [1]

Re: Advice on managing random number generators across threads

2014-06-06 Thread Mars0i
On Friday, June 6, 2014 2:05:16 PM UTC-5, Gunnar Völkel wrote: In Java 7 you would use ThreadLocalRandom you said in another thread. Well, in Java 6 you already have ThreadLocal [1] and thus you are able to build a thread local Random yourself to keep Java 6 as minimum requirement. [1]

Re: Advice on managing random number generators across threads

2014-06-06 Thread Linus Ericsson
(I think your stepwise problem is better to be solved without agents, see below.) I realized that the *rng* actually is conflated, it keeps both the state for the random number generator AND the algorithm used for the random number generation. This is usually not a problem, since the state-size

Re: Advice on managing random number generators across threads

2014-06-06 Thread Lee Spector
I don't know if this will be helpful in your application, or even if it's the best approach for our own work (or if java 1.7 provides a simpler approach?), but FWIW one of my projects deals with the thread-local RNG issue via: https://clojars.org/clj-random -Lee On Jun 6, 2014, at 12:28 PM,

Re: Advice on managing random number generators across threads

2014-06-06 Thread Mars0i
Thanks Lee. It looks like this could be useful. On Friday, June 6, 2014 4:19:11 PM UTC-5, Lee wrote: I don't know if this will be helpful in your application, or even if it's the best approach for our own work (or if java 1.7 provides a simpler approach?), but FWIW one of my projects

Re: Advice on managing random number generators across threads

2014-06-06 Thread Mars0i
Wow. Linus, thanks for the very detailed answer. It sounds as your view is that there's no problem with the logic of my proposed solution, but it seems wasteful to create 100 RNGs, when I don't actually need to have so many of them. Your solutions provide ways to get the same result without

Re: Advice on managing random number generators across threads

2014-06-06 Thread Mars0i
On Friday, June 6, 2014 10:33:04 PM UTC-5, Mars0i wrote: On Friday, June 6, 2014 2:26:25 PM UTC-5, Linus Ericsson wrote: Here I assume that the incoming calls to agents aren't guaranteed to strictly ordered among different agents, even though the agents reside in one of two thread-pools