ZiffRand

SimulationBuilder > Shared > RandNumGenerator?

Professor Robert Ziff's famed random number generator. If you don't want to have any correlations for very long times, this is just what the doctor ordered.


Synopsis

This example shows an instance Ziff's random number generator being created in a Lennard-Jones simulation. It is used to randomize the particle velocities.

#include <glotzilla++.h>
class LennardJonesSimulationRandom : public MdSimulation
{
   public:
        LennardJonesSimulationRandom()
        {                                        
                IntializeParticles();
                SetInteraction(new LennardJones);
                SetForceRoutine(new BruteForce);
                SetBoundaryConditions(new PeriodicBoundary(10));
                SetIntegrationScheme(new VelocityVerletIntegrator);             
        }
        void IntializeParticles()
        {
                //get 216 x,y,z coordinates on a cubic lattice of density 0.85
                ipstream particle_pipe("randbox -n=216 -r=-4,4,-4,4,-4,4 -m=1.1 -i=1000000");
                ZiffRand *mRandomNumberGenerator = new ZiffRand();

                vec_t x;         
                //while we are getting x = {x,y,z} from pipe
                while(particle_pipe >> x)
                {
                        MdPointParticle *p = new MdPointParticle;                  
                        p -> SetPosition(x);
                        vec_t v = mRandomNumberGenerator -> ComputeRandomVecT(-sqrt(3.0), sqrt(3.0));
                        p -> SetVelocity(v);
                        AddParticle(p);
                }
                //close the pipe to mkcrystal
                particle_pipe.close();
        }
};

References

Four-tap shift-registers sequence random number generators