Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Single or multiple random number generators?

  1. Oct 20, 2009 #1
    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.

  2. jcsd
  3. Oct 21, 2009 #2


    User Avatar
    Gold Member

    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook