Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptD3.js randomNormal() Function

D3.js randomNormal() Function

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:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments