# Random numbers in LAMMPS

Dear Lammps users,
I am using Lammps to simulate a system of colloidal particles. I am using Langevin dynamics simulation dynamics. I see that in fix_langevin.cpp the random force used is generated using uniform random number and it is calculated as gamma2*(random->uniform()-0.5). I would assume that this would generate random number between -0.5 to 0.5. Suppose I need to have a temperature of 1.0 how this will make sure that I get that value 1.0. Or <r_i(t)r_i(t’)=\del(t-t’) is obtained in this case. Am I missing something multiplication factor ?
In general I think that in-order to get a value of 1.0 I should 2.0(random->uniform()-1.0) right for a brownian or langevin simulation.

Thank you

Parvathy

Dear Lammps users,
I am using Lammps to simulate a system of colloidal particles. I am using Langevin dynamics simulation dynamics. I see that in fix_langevin.cpp the random force used is generated using uniform random number and it is calculated as gamma2*(random->uniform()-0.5). I would assume that this would generate random number between -0.5 to 0.5. Suppose I need to have a temperature of 1.0 how this will make sure that I get that value 1.0. Or <r_i(t)r_i(t')=\del(t-t') is obtained in this case. Am I missing something multiplication factor ?

yes, you even quoted it. the magic is in the value of "gamma2". you
won't get a number between -0.5 and 0.5 but between -gamma2*0.5 and
gamma2*0.5

In general I think that in-order to get a value of 1.0 I should 2.0(random->uniform()-1.0) right for a brownian or langevin simulation.

your thinking is wrong.

axel.

Dear Lammps users,

Thank you axel for the mail.

Dear Lammps users,
I am using Lammps to simulate a system of colloidal particles. I am using Langevin dynamics simulation dynamics. I see that in fix_langevin.cpp the random force used is generated using uniform random number and it is calculated as gamma2*(random->uniform()-0.5). I would assume that this would generate random number between -0.5 to 0.5. Suppose I need to have a temperature of 1.0 how this will make sure that I get that value 1.0. Or <r_i(t)r_i(t’)=\del(t-t’) is obtained in this case. Am I missing something multiplication factor ?

yes, you even quoted it. the magic is in the value of “gamma2”. you
won’t get a number between -0.5 and 0.5 but between -gamma2*0.5 and

The factor gamma2 has value gamma2 = gfactor2[i]*tsqrt;

gfactor2[i] = sqrt(atom->mass[i]) *
sqrt(24.0*force->boltz/t_period/update->dt/force->mvv2e) /
force->ftm2v;

And LAMMPS documentation says Fran is proportional to sqrt(Kb T m / (dt damp)) . Can you please explain why there is a factor 24 ?

In general I think that in-order to get a value of 1.0 I should 2.0(random->uniform()-1.0) right for a brownian or langevin simulation.

your thinking is wrong.

sorry I meant this 2*random->uniform()-1.0 to get the temperature to be one ? That generate values between -1 to 1 rather than -0.5 to -0.5
Best Regards:

Parvathy.

sorry, but this is not the place to give you a lecture on how a
langevin thermostat is derived and implemented. please refer to the
published literature and text books instead. i am quite confident,
that the implementation is correct.

axel.

For factor 24, see this post from Steve from almost 10 years ago: https://lammps.sandia.gov/threads/msg09923.html