]> sourceware.org Git - systemtap.git/commitdiff
PR1062: runtime function
authorCharley Wang <chwang@redhat.com>
Wed, 23 Sep 2009 18:00:33 +0000 (14:00 -0400)
committerFrank Ch. Eigler <fche@elastic.org>
Wed, 23 Sep 2009 18:03:56 +0000 (14:03 -0400)
* arith.c (_stp_random_pm_u): New function.

runtime/arith.c

index d1d0da29b0657d657e2befcfdf0c1eefbe377e93..4b0e6c9e78a6ee9a5a774da106d8e45ddf7134d7 100644 (file)
@@ -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 */
This page took 0.306982 seconds and 5 git commands to generate.