Yes, you can use one instance of Random
. The backing implementation for nextGaussian()
is Box, Muller, & Marsaglia's Polar method which generates Gaussians in pairs. The first call to it will generate a pair and return the first of the two values, the next call will just return the previously generated second value. The pairs are mathematically independent(*) if the uniform inputs are. In theory this can be a problem if the uniforms come from a linear congruential generator with a bad lattice structure, but Java's LCG is pretty decent and in practice the results can be considered effectively independent for most uses.
The bigger question would be why do you need two different methods to be sources of Gaussians? What does that gain you that just calling rand.nextGaussian()
wouldn't achieve?
(*) - the Gaussian return values are sine & cosine components of a vector generated in polar coordinates, and are thus orthogonal. For Gaussians, orthogonality implies independent.