- #1
Feldoh
- 1,342
- 3
I'm trying to program a java simulation of some particles in a box. Anyways I want to initialize the particles with random velocities such that on average they're distributed around some velocity.
To do this I was thinking about using the nextGaussian() method.
Anyways I was initializing my particles with something like (in a simplified version):
Where particle takes in 4 doubles: xpos,ypos,xvel,yvel.
Anyways I'm worried about the way java stores the variables. I'm worried that my particle class will store the addr to r.nextGaussian rather than just a number. This would be bad since then everytime I would call the xvel or yvel the number would change.
Is that assessment correct and does anyone know of a way to fix it if this is correct?
To do this I was thinking about using the nextGaussian() method.
Anyways I was initializing my particles with something like (in a simplified version):
Code:
Random r = new Random();
double avg = 10;
Particle a = new Particle(xpos,ypos, r.nextGaussian()+avg,r.nextGaussian()+avg);
Where particle takes in 4 doubles: xpos,ypos,xvel,yvel.
Anyways I'm worried about the way java stores the variables. I'm worried that my particle class will store the addr to r.nextGaussian rather than just a number. This would be bad since then everytime I would call the xvel or yvel the number would change.
Is that assessment correct and does anyone know of a way to fix it if this is correct?