about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-20 23:07:51 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-20 23:07:51 -0700
commite62ef075da85367425862ac399f12ff3991349de (patch)
treea31257ea81eb4e303c03afc9168181af10348cc8
parent1c57bab69a332f1a2da98f042fd612e564af5cda (diff)
downloadmu-e62ef075da85367425862ac399f12ff3991349de.tar.gz
3537
-rw-r--r--068random.mu19
1 files changed, 19 insertions, 0 deletions
diff --git a/068random.mu b/068random.mu
index d22d453f..8f7a53b7 100644
--- a/068random.mu
+++ b/068random.mu
@@ -53,3 +53,22 @@ scenario random-numbers-in-scenario [
     8 <- 1  # end of stream
   ]
 ]
+
+def random-in-range generator:&:stream:num, start:num, end:num -> result:num, fail?:bool, generator:&:stream:num [
+  local-scope
+  load-ingredients
+  result, fail?, generator <- random generator
+  return-if fail?
+  delta:num <- subtract end, start
+  _, result <- divide-with-remainder result, delta
+  result <- add result, start
+]
+
+scenario random-in-range [
+  local-scope
+  source:&:stream:num <- assume-random-numbers 91
+  1:num/raw <- random-in-range source, 40, 50
+  memory-should-contain [
+    1 <- 41
+  ]
+]