Loading...
Logo
Processing Forum
Hi

I was wondering if anybody knows if the VerletPhysics lib uses some kind of randomness that is unaffected by processings own randomSeed(int x) command? 
I am testing a program and keep getting slightly different oucomes eventhough I use randomSeed?

best
Jacob

Replies(2)

There're no random numbers used within the physics sim, but I'm assuming you're using the physics with randomly created particle positions and use Vec2D/3D.randomVector() or jitter() (the latter is actually used by AttractionBehavior). Since toxiclibs knows nothing about Processing you're right that setting randomSeed() in P5 doesn't have any impact.

Due to the design of Processing there's also no way to obtain a direct reference to P5's internal random generator ( it only is visible within the processing.core package, maybe submit a ticket to change that), however you can configure the toxiclibs default instance in several ways:
Copy code
  1. import toxi.math.*;

  2. // just seed the default generator
  3. MathUtils.RND.setSeed(23);

  4. // or actually use an external generator as the default within toxiclibs
  5. // all classes which use random numbers will make use of this default generator:
  6. // e.g. Vec2D.randomVector(), TColor.newRandom(), FloatRange.pickRandom() etc.
  7. Random rnd=new Random(23);
  8. MathUtils.setDefaultRandomGenerator(rnd);
The latter option is useful for plugging in faster and/or qualitative better options than the default Java Random implementation, e.g. the famous Mersenne Twister...

Once you've seeded that default generator, it will also deliver the ever same results.
Thank you for the quick answer and for a great library Toxmeister!