Normal distribution of random numbers
var randomHeight = random(200, 300);
random()produces. People’s heights are not uniformly distributed; there are a great deal more people of average height than there are very tall or very short ones. To simulate nature, we may want it to be more likely that our monkeys are of average height (250 pixels), yet still allow them to be, on occasion, very short or very tall.
|Резултат||Difference from Mean||Варианса|
|85||= 3.7||= 13.69|
|82||= 0.7||= 0.49|
|88||= 6.7||= 44.89|
Randomobject provided by ProcessingJS.
Random, we must first instantiate a new
Randomobject, passing in 1 as the parameter. We call that variable "generator" because what we've created can be basically thought of as a random number generator.
var generator = new Random(1);
draw(), it’s as easy as calling the function
var num = generator.nextGaussian(); println(num);
nextGaussian()function returns a normal distribution of random numbers with the following parameters: a mean of zero and a standard deviation of one. Let’s say we want a mean of 200 (the center horizontal pixel in a window of width 400) and a standard deviation of 60 pixels. We can adjust the value to our parameters by multiplying it by the standard deviation and adding the mean.
var standardDeviation = 60; var mean = 200; var x = standardDeviation * num + mean;