about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-05-23 14:39:10 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-05-23 14:39:10 -0700
commit8cb4e3653bbaaf8a445c30d63fc6bad4c5164e87 (patch)
tree894d48f186c5d2ed8159f1f7212a1cc8aae3656c
parent40be252286bc89b4930049b9ab2cbac1f54a9357 (diff)
downloadmu-8cb4e3653bbaaf8a445c30d63fc6bad4c5164e87.tar.gz
1438
-rw-r--r--064random.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/064random.cc b/064random.cc
new file mode 100644
index 00000000..98ec3156
--- /dev/null
+++ b/064random.cc
@@ -0,0 +1,42 @@
+:(before "End Primitive Recipe Declarations")
+RANDOM,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["random"] = RANDOM;
+:(before "End Primitive Recipe Implementations")
+case RANDOM: {
+  products.resize(1);
+  // todo: replace rand()
+  products.at(0).push_back(rand());
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+MAKE_RANDOM_NONDETERMINISTIC,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["make-random-nondeterministic"] = MAKE_RANDOM_NONDETERMINISTIC;
+:(before "End Primitive Recipe Implementations")
+case MAKE_RANDOM_NONDETERMINISTIC: {
+  srand(time(NULL));
+  break;
+}
+
+:(before "End Primitive Recipe Declarations")
+ROUND,
+:(before "End Primitive Recipe Numbers")
+Recipe_number["round"] = ROUND;
+:(before "End Primitive Recipe Implementations")
+case ROUND: {
+  assert(scalar(ingredients.at(0)));
+  products.resize(1);
+  products.at(0).push_back(rint(ingredients.at(0).at(0)));
+  break;
+}
+
+:(scenario round_to_nearest_integer)
+recipe main [
+  1:number <- round 12.2
+]
++mem: storing 12 in location 1
+
+:(before "End Includes")
+#include<math.h>