summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorDavid Smith <dsmith@redhat.com>2009-09-24 08:11:09 -0500
committerDavid Smith <dsmith@redhat.com>2009-09-24 08:11:09 -0500
commitc7687aa3f93a1c831b1c8f3f2e6271b9802923a5 (patch)
tree85a132723be8d07a4b806d7168b6cc83ae529e5f /runtime
parentd3e3db27d3410fe52e826ff4f76e5a84d192cbb2 (diff)
parent1c625307539ca5a0bae6a7a6e297f8d8841a8911 (diff)
downloadsystemtap-steved-c7687aa3f93a1c831b1c8f3f2e6271b9802923a5.tar.gz
systemtap-steved-c7687aa3f93a1c831b1c8f3f2e6271b9802923a5.tar.xz
systemtap-steved-c7687aa3f93a1c831b1c8f3f2e6271b9802923a5.zip
Merge branch 'master' of ssh://sources.redhat.com/git/systemtap
Diffstat (limited to 'runtime')
-rw-r--r--runtime/arith.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/runtime/arith.c b/runtime/arith.c
index d1d0da29..4c818a76 100644
--- a/runtime/arith.c
+++ b/runtime/arith.c
@@ -84,26 +84,34 @@ static int64_t _stp_mod64 (const char **error, int64_t x, int64_t y)
}
-#ifndef _STP_TEST_
-/** Return a random integer between -n and n.
+/** Return a random integer between 0 and n - 1.
* @param n how far from zero to go. Make it positive but less than a million or so.
*/
-static int _stp_random_pm (int n)
+static unsigned long _stp_random_u (unsigned long 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);
+
+ return (n == 0 ? 0 : seed % n);
}
-#endif /* _STP_TEST_ */
+
+
+/** 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.
+ */
+static int _stp_random_pm (unsigned n)
+{
+ return -(int)n + (int)_stp_random_u (2*n + 1);
+}
+
#if defined (__i386__) || defined (__arm__)