summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/ChangeLog4
-rw-r--r--runtime/arith.c24
2 files changed, 27 insertions, 1 deletions
diff --git a/runtime/ChangeLog b/runtime/ChangeLog
index 05367f27..f4f791dd 100644
--- a/runtime/ChangeLog
+++ b/runtime/ChangeLog
@@ -1,3 +1,7 @@
+2005-08-19 Frank Ch. Eigler <fche@elastic.org>
+
+ * arith.c (_stp_random_pm): New function.
+
2005-08-19 Martin Hunt <hunt@redhat.com>
* print.c: Change ifdefs to STP_RELAYFS.
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_ */