diff src/paranormal/libcalc/function.c @ 1175:7ae024f5d91b trunk

[svn] - libcalc (paranormal virtual evaluation machine): add rand() instruction, global registers (global_reg0-reg99).
author nenolod
date Fri, 08 Jun 2007 10:56:12 -0700
parents a9f1bd76a3e6
children 44d28af95a23
line wrap: on
line diff
--- a/src/paranormal/libcalc/function.c	Fri Jun 08 08:51:30 2007 -0700
+++ b/src/paranormal/libcalc/function.c	Fri Jun 08 10:56:12 2007 -0700
@@ -73,6 +73,10 @@
   return (y == 0) ? 0 : (x / y);
 }
 
+static double f_rand (ex_stack *stack) {
+  return rand() % pop (stack);
+}
+
 /* */
 
 static const func_t init[] = {
@@ -85,6 +89,7 @@
   { "log", f_log },
   { "if", f_if },
   { "div", f_div }
+  { "rand", f_rand }
 };
 
 int function_lookup (const char *name) {