Thursday, November 20, 2025
HomeLanguagesJavascriptD3.js randomBates() Function

D3.js randomBates() Function

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:

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

Dominic
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6775 POSTS0 COMMENTS
Nicole Veronica
11924 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6903 POSTS0 COMMENTS
Ted Musemwa
7159 POSTS0 COMMENTS
Thapelo Manthata
6859 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS