The randomNormal() function is used to return a function that gives a random number based on Normal distribution or Gaussian distribution.
Syntax:
d3.randomNormal(mu, sigma);
Parameters: It takes the two parameters given above and described below.
- mu: It is the expected value of the number. If mu is not given then it is considered as 0.
- sigma: The number is generated with a certain standard deviation called sigma.
Returns: It returns a function.
Below given are a few examples of the above function.
Example 1: When mu is given.
html
<!DOCTYPE html> < html lang="en"> < head > < meta charset="UTF-8"> < meta name="viewport" content=" width = device -width, initial-scale = 1 .0"> < title >Document</ title > </ head > < style > </ style > < body > <!-- Fetching from CDN of D3.js --> < script type = "text/javascript" src = "https://d3js.org/d3.v4.min.js"> </ script > < script > // The output may be different on different machines. console.log(d3.randomNormal(10, 10)()) console.log(d3.randomNormal(10, 10)()) console.log(d3.randomNormal(10, 10)()) console.log(d3.randomNormal(10, 10)()) console.log(d3.randomNormal(10, 10)()) </ script > </ body > </ html > |
Output:
Example 2: When mu is not given.
html
<!DOCTYPE html> < html lang="en"> < head > < meta charset="UTF-8"> < meta name="viewport" content=" width = device -width, initial-scale = 1 .0"> < title >Document</ title > </ head > < style > </ style > < body > <!-- Fetching from CDN of D3.js --> < script type = "text/javascript" src = "https://d3js.org/d3.v4.min.js"> </ script > < script > // The output may be different on different machines. console.log(d3.randomNormal(5)()) console.log(d3.randomNormal(5)()) console.log(d3.randomNormal(5)()) console.log(d3.randomNormal(5)()) console.log(d3.randomNormal(5)()) console.log(d3.randomNormal(5)()) </ script > </ body > </ html > |
Output: