| changeset 47 | c0b4a8b5a012 |
| 46:efd9c589177a | 47:c0b4a8b5a012 |
|---|---|
1 d3.random = { |
|
2 normal: function(mean, deviation) { |
|
3 if (arguments.length < 2) deviation = 1; |
|
4 if (arguments.length < 1) mean = 0; |
|
5 return function() { |
|
6 var x, y, r; |
|
7 do { |
|
8 x = Math.random() * 2 - 1; |
|
9 y = Math.random() * 2 - 1; |
|
10 r = x * x + y * y; |
|
11 } while (!r || r > 1); |
|
12 return mean + deviation * x * Math.sqrt(-2 * Math.log(r) / r); |
|
13 }; |
|
14 } |
|
15 }; |