# Generating random number in lammps

I want to generate random number every time, but seems following command is only providing me a constant number.
variable number equal ceil(random(1,1,10)*10000)
print \${number}

That is because you give it a range from 1 to 1.
The number returned is an integer.

So try something like the following:

``````variable number equal ceil(random(1,1000000000,10)/100000.0)
print \${number}
print \${number}
print \${number}
print \${number}
print \${number}
print \${number}
``````

clear
units metal
boundary p p p
atom_style atomic
atom_modify map array
atom_modify sort 0 0.0
variable lp equal "3.33"
lattice bcc \${lp} orient x 1 0 0 orient y 0 1 0 orient z 0 0 1
region whole block 0 1 0 1 0 1 units lattice
create_box 3 whole
create_atoms 1 region whole
replicate 3 3 3
group iron type 1
variable number equal ceil(random(1,1000000000,10)/100000.0)
print \${number}
set group iron type/fraction 2 0.203703704 \${number}
set group iron type/fraction 3 0.055555556 \${number}
mass * 1
# ---------- Define Interatomic Potential ---------------------
pair_style lj/cut 3.0
pair_coeff * * 1 1

neighbor 2.0 bin
neigh_modify delay 10 check yes
run 0

every time it is printing 2355, I want different number with every run

Then you have to use a different seed for each run!

The whole point of having pseudo random number generators with a seed is to make calculations repeatable. If your shell is bash, this can be easily done by using the random number generator embedded in bash.

``````variable rnseed index 10
variable number equal ceil(random(1,1000000000,\${rnseed})/100000.0)
print \${number}
``````

and then using:
`./lmp -in in.random -v rnseed \$RANDOM`

I have to correct my statement. After reviewing the source code, I realize that the reported value from the random function is a double precision floating-point number and not an integer. The problem is, however, giving a range of 1 to 1, which is no range at all. So if you want random numbers between 0 and 1 as it seems you want to get, you would have to use `random(0,1,\${rnseed})`.

Thanks a lot !!!