aboutsummaryrefslogtreecommitdiff
path: root/builtins
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-08-16 14:18:23 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-08-16 14:18:23 -0400
commit04714e00d781235590553446301ac7e5818b3455 (patch)
tree94f6a7ee3ebc3a49f5cbe6560e08255e9d7087ef /builtins
parent0f1c475bb485953ad0ae98fbb5a96d24c53d8414 (diff)
Add Bool:random(p=0.5)
Diffstat (limited to 'builtins')
-rw-r--r--builtins/bool.c5
-rw-r--r--builtins/bool.h1
2 files changed, 6 insertions, 0 deletions
diff --git a/builtins/bool.c b/builtins/bool.c
index 1e741be1..af2f0ac7 100644
--- a/builtins/bool.c
+++ b/builtins/bool.c
@@ -40,6 +40,11 @@ public Bool_t Bool$from_text(CORD text, bool *success)
}
}
+public Bool_t Bool$random(double p)
+{
+ return (drand48() < p);
+}
+
public const TypeInfo $Bool = {
.size=sizeof(bool),
.align=__alignof__(bool),
diff --git a/builtins/bool.h b/builtins/bool.h
index 356889d1..716ddd5b 100644
--- a/builtins/bool.h
+++ b/builtins/bool.h
@@ -14,6 +14,7 @@
CORD Bool$as_text(const bool *b, bool colorize, const TypeInfo *type);
bool Bool$from_text(CORD text, bool *success);
+Bool_t Bool$random(double p);
extern const TypeInfo $Bool;