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


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

randomNormal()函數用於返回基於正態分布或高斯分布給出隨機數的函數。

用法:

d3.randomNormal(mu, sigma);

參數:它采用上麵給定和下麵描述的兩個參數。

  • mu:它是數字的期望值。如果未提供mu,則將其視為0。
  • sigma:生成的數字具有一定的標準偏差,稱為sigma。

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

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



範例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 ouput may be different on different machines. 
    console.log(d3.randomNormal(10, 10)()) 
    console.log(d3.randomNormal(10, 10)()) 
    console.log(d3.randomNormal(10, 10)()) 
    console.log(d3.randomNormal(10, 10)()) 
    console.log(d3.randomNormal(10, 10)()) 
  </script> 
</body> 
</html>

輸出:

範例2:當畝不給。

<!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 ouput may be different on different machines. 
    console.log(d3.randomNormal(5)()) 
    console.log(d3.randomNormal(5)()) 
    console.log(d3.randomNormal(5)()) 
    console.log(d3.randomNormal(5)()) 
    console.log(d3.randomNormal(5)()) 
    console.log(d3.randomNormal(5)()) 
  </script> 
</body> 
</html>

輸出:




相關用法


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