summaryrefslogtreecommitdiffstats
path: root/runtime/arith.c
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/arith.c')
-rw-r--r--runtime/arith.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/runtime/arith.c b/runtime/arith.c
index 175cc4e8..0200afa6 100644
--- a/runtime/arith.c
+++ b/runtime/arith.c
@@ -2,9 +2,10 @@
#define _ARITH_C_
/** @file arith.
- * @brief Implements 64-bit signed division/multiplication.
+ * @brief Implements various arithmetic-related helper functions
*/
+
struct context;
void _stp_divmod64 (unsigned *errorcount, int64_t x, int64_t y,
int64_t *quo, int64_t *rem);
@@ -75,5 +76,26 @@ void _stp_divmod64 (unsigned *errorcount, int64_t x, int64_t y,
}
+/** Return a random integer between -n and n.
+ * @param n how far from zero to go. Make it positive but less than a million or so.
+ */
+int _stp_random_pm (int n)
+{
+ static unsigned long seed;
+ static int initialized_p = 0;
+
+ if (unlikely (! initialized_p))
+ {
+ seed = (unsigned long) jiffies;
+ initialized_p = 1;
+ }
+
+ /* from glibc rand man page */
+ seed = seed * 1103515245 + 12345;
+
+ return (seed % (2*n+1)-n);
+}
+
+
#endif /* _ARITH_C_ */