PDA

View Full Version : Single or multiple random number generators?


mtanti
Oct20-09, 03:19 PM
I'm programming in Java and using the Random class and I'm not sure if it makes a difference whether I use a single accessible Random object for the whole program or if I should create multiple instances (one for each object needing it?). Are there disadvantages to using one instead of the other?

I'm assuming that it would help to be able to reuse the same seed on a single random object in order to re-create the same sequence of random numbers during debugging and comparisons.

Thanks.

DavidSnider
Oct21-09, 12:21 PM
I'm programming in Java and using the Random class and I'm not sure if it makes a difference whether I use a single accessible Random object for the whole program or if I should create multiple instances (one for each object needing it?). Are there disadvantages to using one instead of the other?

I'm assuming that it would help to be able to reuse the same seed on a single random object in order to re-create the same sequence of random numbers during debugging and comparisons.

Thanks.

It depends on the application. If you can get away with just one that is best. Instantiating new objects takes both processor and memory resources.