|
Last change
on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Prototype 1.1
|
-
Property mode
set to
100644
|
|
File size:
489 bytes
|
| Line | |
|---|
| 1 | import defaultSource from "./defaultSource.js";
|
|---|
| 2 |
|
|---|
| 3 | export default (function sourceRandomGeometric(source) {
|
|---|
| 4 | function randomGeometric(p) {
|
|---|
| 5 | if ((p = +p) < 0 || p > 1) throw new RangeError("invalid p");
|
|---|
| 6 | if (p === 0) return () => Infinity;
|
|---|
| 7 | if (p === 1) return () => 1;
|
|---|
| 8 | p = Math.log1p(-p);
|
|---|
| 9 | return function() {
|
|---|
| 10 | return 1 + Math.floor(Math.log1p(-source()) / p);
|
|---|
| 11 | };
|
|---|
| 12 | }
|
|---|
| 13 |
|
|---|
| 14 | randomGeometric.source = sourceRandomGeometric;
|
|---|
| 15 |
|
|---|
| 16 | return randomGeometric;
|
|---|
| 17 | })(defaultSource);
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.