diff options
author | Charley Wang <chwang@redhat.com> | 2009-09-23 14:00:33 -0400 |
---|---|---|
committer | Frank Ch. Eigler <fche@elastic.org> | 2009-09-23 14:03:56 -0400 |
commit | dc0c46f5f74a9e0468236b31c8d9364eb24c3624 (patch) | |
tree | 14a3018ef1781d510b3951092796d0e06aecefb7 /runtime/arith.c | |
parent | 430411789c9c9540a8260bedc76d86fdf6053713 (diff) | |
download | systemtap-steved-dc0c46f5f74a9e0468236b31c8d9364eb24c3624.tar.gz systemtap-steved-dc0c46f5f74a9e0468236b31c8d9364eb24c3624.tar.xz systemtap-steved-dc0c46f5f74a9e0468236b31c8d9364eb24c3624.zip |
PR1062: runtime function
* arith.c (_stp_random_pm_u): New function.
Diffstat (limited to 'runtime/arith.c')
-rw-r--r-- | runtime/arith.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/runtime/arith.c b/runtime/arith.c index d1d0da29..4b0e6c9e 100644 --- a/runtime/arith.c +++ b/runtime/arith.c @@ -106,6 +106,28 @@ static int _stp_random_pm (int n) #endif /* _STP_TEST_ */ +#ifndef _STP_TEST_ +/** 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_u (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 % n); +} +#endif /* _STP_TEST_ */ + + #if defined (__i386__) || defined (__arm__) /* 64-bit division functions extracted from libgcc */ |