Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

D3.js randomBates() Function

  • Last Updated : 31 Jul, 2020

The randomBates() function in D3.js returns a function that is used for generating random numbers. This function that is returned is based on the Bates distribution.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

randomBates(n)

Parameters: This function accepts a single parameter as mentioned above and described below:

  • n: It is any number that is used with bates distribution to generate the random number.

Returns: It returns the function.



Below given are a few examples of the above function.

Example 1:

HTML




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0">
  <title>D3.js randomBates() Function</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>
    // Output may be different each time 
    // the function is run
    console.log(d3.randomBates(0)());  
    console.log(d3.randomBates(1)());  
    console.log(d3.randomBates(2)());  
    console.log(d3.randomBates(3)());  
    console.log(d3.randomBates(4)());  
    console.log(d3.randomBates(5)());  
  </script>
</body>
</html>

Output:

Example 2:

HTML




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0">
  <title>D3.js randomBates() Function</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>
    // Output may be different each time 
    // the function is run
    console.log(d3.randomBates(-10)());  
    console.log(d3.randomBates(-1)(85)); 
    // Please note n is between 1 and 0 then 
    // random number 
    // Generated is greater than 1 
    console.log(d3.randomBates(0.0052)());  
    console.log(d3.randomBates(.0085)());  
    console.log(d3.randomBates(0.005)());  
    console.log(d3.randomBates(1.025)());  
  </script>
</body>
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :