aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers.ts')
-rw-r--r--src/helpers.ts5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/helpers.ts b/src/helpers.ts
index 8a17555..9bb1eac 100644
--- a/src/helpers.ts
+++ b/src/helpers.ts
@@ -6,3 +6,8 @@ export const toKebabCase = (str: string) => str
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
?.map(x => x.toLowerCase())
.join('-');
+
+export function random(p: number): boolean {
+ if (p < 0 || p > 1) throw Error("Wrong probability - " + p)
+ return Math.random() < p;
+}