extra-rand 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -30,6 +30,11 @@ function randomIntInclusive(min: number, max: number): number
30
30
 
31
31
  The function returns an integer in the range `[Math.ceil(min), Math.floor(max)]`.
32
32
 
33
+ ### randomBool
34
+ ```ts
35
+ function randomBool(probabilityOfTrue: number): boolean
36
+ ```
37
+
33
38
  ### randomByWeight
34
39
  ```ts
35
40
  function randomByWeight(weights: number[]): number
package/lib/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './random';
2
2
  export * from './random-int';
3
3
  export * from './random-int-inclusive';
4
+ export * from './random-bool';
4
5
  export * from './random-by-weight';
5
6
  export * from './map-to-range';
6
7
  export * from './map-to-index-by-weight';
package/lib/index.js CHANGED
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./random"), exports);
18
18
  __exportStar(require("./random-int"), exports);
19
19
  __exportStar(require("./random-int-inclusive"), exports);
20
+ __exportStar(require("./random-bool"), exports);
20
21
  __exportStar(require("./random-by-weight"), exports);
21
22
  __exportStar(require("./map-to-range"), exports);
22
23
  __exportStar(require("./map-to-index-by-weight"), exports);
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,+CAA4B;AAC5B,yDAAsC;AACtC,qDAAkC;AAElC,iDAA8B;AAC9B,2DAAwC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,+CAA4B;AAC5B,yDAAsC;AACtC,gDAA6B;AAC7B,qDAAkC;AAElC,iDAA8B;AAC9B,2DAAwC"}
@@ -0,0 +1 @@
1
+ export declare function randomBool(probabilityOfTrue: number): boolean;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.randomBool = void 0;
4
+ const random_1 = require("./random");
5
+ function randomBool(probabilityOfTrue) {
6
+ return (0, random_1.random)(0, 1) < probabilityOfTrue;
7
+ }
8
+ exports.randomBool = randomBool;
9
+ //# sourceMappingURL=random-bool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random-bool.js","sourceRoot":"","sources":["../src/random-bool.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AAEjC,SAAgB,UAAU,CAAC,iBAAyB;IAClD,OAAO,IAAA,eAAM,EAAC,CAAC,EAAE,CAAC,CAAC,GAAG,iBAAiB,CAAA;AACzC,CAAC;AAFD,gCAEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extra-rand",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Yet another random library",
5
5
  "keywords": [
6
6
  "random"
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './random'
2
2
  export * from './random-int'
3
3
  export * from './random-int-inclusive'
4
+ export * from './random-bool'
4
5
  export * from './random-by-weight'
5
6
 
6
7
  export * from './map-to-range'
@@ -0,0 +1,5 @@
1
+ import { random } from './random'
2
+
3
+ export function randomBool(probabilityOfTrue: number): boolean {
4
+ return random(0, 1) < probabilityOfTrue
5
+ }