當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


d3.js randomExponential()用法及代碼示例

randomExponential()函數用於返回根據 index 分布生成隨機數的函數。

用法:

d3.randomExponential(lambda);

參數:它僅采用上麵給出和下麵描述的一個參數。

  • lambda: index 分布函數的比率等於泊鬆過程中事件之間的時間。

返回值:它返回一個函數。

注意:每次運行該函數時,輸出值可能都不同。



下麵給出了上述函數的一些示例。

範例1:當λ大於1時。

<!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 value of the output may be 
 different each time the function is run.*/ 
    console.log(d3.randomExponential(5)()) 
    console.log(d3.randomExponential(5)()) 
    console.log(d3.randomExponential(5)()) 
    console.log(d3.randomExponential(5)()) 
    console.log(d3.randomExponential(5)()) 
  </script> 
</body> 
</html>

輸出:

範例2:當lambda的值小於一時。

<!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 value of the output may be 
 different each time the function is run.*/ 
    console.log(d3.randomExponential(0.5)()) 
/* Smaller the lamba greater the random value generated. 
    console.log(d3.randomExponential(0.05)()) 
    console.log(d3.randomExponential(0.005)()) 
    console.log(d3.randomExponential(0.0005)()) 
  </script> 
</body> 
</html>

輸出:




相關用法


注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js randomExponential() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。