Open In App

D3.js randomBates() Function

Last Updated : 31 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:

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:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads