Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Random.nextgaussian() sample values from a distribution with different mean and standard deviation?

Tags:

This is a combined Java and basic math question. The documentation from Random.nextGaussian() states that it samples from a normal distribution with mean 0 and standard deviation 1. What if I wanted to sample from a normal distribution with a different mean and variance?

like image 615
darkhipo Avatar asked Jul 31 '15 19:07

darkhipo


People also ask

What distribution would a random number generator have?

This form allows you to generate random numbers from a Gaussian distribution (also known as a normal distribution). The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs.

What is the function used to generate a random number based on normal distribution?

X = randn returns a random scalar drawn from the standard normal distribution. X = randn( n ) returns an n -by- n matrix of normally distributed random numbers.

Are random numbers normally distributed?

. A random variable with a Gaussian distribution is said to be normally distributed, and is called a normal deviate. Normal distributions are important in statistics and are often used in the natural and social sciences to represent real-valued random variables whose distributions are not known.

Which function gives the probability of normally distributed random number to be less that the value of a given number?

pnorm() This function gives the probability of a normally distributed random number to be less that the value of a given number. It is also called "Cumulative Distribution Function".


1 Answers

The short answer is

Random r = new Random(); double mySample = r.nextGaussian()*desiredStandardDeviation+desiredMean; 

For example this answer is given here: http://www.javamex.com/tutorials/random_numbers/gaussian_distribution_2.shtml

I didn't really understand why this worked, but after looking into it a bit I think I figured it out. The mean of the sample point is 0, and the standard deviation is 1; that means that the original sample is also its own z-score ( https://en.wikipedia.org/wiki/Standard_score ). To quote from wikipedia "The absolute value of z represents the distance between the raw score and the population mean in units of the standard deviation". The formula is z=(x-mean)/stdev, so with the default values z=x. If we wanted to retain the z score for the sample but change the mean and stdev what would we do?

z*stdev + mean = x' where z=x, and x' represents the sample from the distribution with the desired mean and standard deviation.

like image 173
darkhipo Avatar answered Oct 04 '22 18:10

darkhipo