[lammps-users] Random number generator in input

Hello,

How could I get a random number in the script file itself?

Ting Li (KUL)

If you mean, put a random # seed in your input script, then
you just type it in. If you want a series of seeds, e.g. to run
multiple simulations and re-init the velocities, I usually cut-and-paste
a set of them from a WWW site like
http://www.random.org/integers

Steve

Got it! I meant the later case. Thanks!
Would that be nicer if adding a math function rand() for the variable command?
(Maybe also useful in some other situation)

Ting Li (KUL)

The problem with using a system RNG is irreproducibility. LAMMPS has
its own RNGs which you need to give a seed to, They they are portable
and reproducible on all machines. What is your reasons for wanting
to generate a random number in the middle of an input script, and how
it different that needing a seed. I.e. do you need many random numbers?

Steve

Hi, Steve,

Right now I just need to repeat many runs with different seeds.
The solution you gave works fine. I just manually put some seeds in an index variable.

However I think it would be useful if lammps exposes its internal random number generator.
I.e. add a seed() and a rand() function. The user can set a seed e.g. in the beginning of a input file
and get pseudo random numbers in the following calls. Yes, normally in a script not that many
random numbers is needed. But if this function is available, together with the math operations
have been implemented for "variable" command (like sqrt(), ceil(), etc. http://lammps.sandia.gov/doc/variable.html),
user can perform random operations on any scalar and vector values output by various commands,
fixes or computes. (for vector variables, many random numbers can be required) Again this is just
a suggestion for flexibility not a request.

Ting Li (KUL)

sure - I'll think about it.

Steve