当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


d3.js randomBates()用法及代码示例


D3.js中的randomBates()函数返回用于生成随机数的函数。返回的此函数基于Bates分布。

用法:

randomBates(n)

参数:该函数接受如上所述和以下描述的单个参数:

  • n:它是与bates分发一起使用以生成随机数的任何数字。

返回值:它返回函数。

下面给出了上述函数的一些示例。



范例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>

输出:

范例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>

输出:




相关用法


注:本文由纯净天空筛选整理自tarun007大神的英文原创作品 D3.js randomBates() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。