]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a simple random number generator to m_libcbase so we don't have
authorNicholas Nethercote <njn@valgrind.org>
Fri, 8 Jul 2005 04:08:59 +0000 (04:08 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Fri, 8 Jul 2005 04:08:59 +0000 (04:08 +0000)
to use the one from glibc.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4130

coregrind/m_libcbase.c
coregrind/m_skiplist.c
include/pub_tool_libcbase.h

index 7369cb38ceddd8a1944fef33105e7ca52a6b1628..f8c4275edd7ed7ce6880268ab7bd78604efcce6f 100644 (file)
@@ -471,6 +471,21 @@ void VG_(ssort)( void* base, SizeT nmemb, SizeT size,
    #undef SORT
 }
 
+static UInt seed = 0;
+
+void VG_(srandom)(UInt s)
+{
+   seed = s;
+}
+
+// This random number generator is based on the one suggested in Kernighan
+// and Ritchie's "The C Programming Language".
+UInt VG_(random)(void)
+{
+   seed = (1103515245*seed + 12345);
+   return seed;
+}
+
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
 /*--------------------------------------------------------------------*/
index 796b1d39d7d4b1eb326285c52a5d439c4ee37722..f9ca18806847e0e790650c84bf4888555d73ed8f 100644 (file)
@@ -93,8 +93,6 @@
 #include "pub_core_mallocfree.h"
 #include "pub_core_skiplist.h"
 
-#include <stdlib.h>
-
 #define SKIPLIST_DEBUG 0
 
 #define SK_MAXHEIGHT   20      /* 2^20 elements */
@@ -121,7 +119,7 @@ static inline Int get_height(void)
 {
    UInt ret = 0;
 
-   while((ret < SK_MAXHEIGHT - 1) && (random() & 1))
+   while((ret < SK_MAXHEIGHT - 1) && (VG_(random)() & 1))
       ret++;
 
    return ret;
index fb59b39b93e1a539c84dd91070441c2a1cf711e3..d1f7f5c1d15eceb24fb91074bd015d04fbacee7e 100644 (file)
@@ -114,6 +114,11 @@ extern void VG_(ssort)( void* base, SizeT nmemb, SizeT size,
 /* Returns the base-2 logarithm of x. */
 extern Int VG_(log2) ( Int x );
 
+// A pseudo-random number generator returning a random UInt,  and its
+// seed function.
+extern void VG_(srandom) ( UInt seed );
+extern UInt VG_(random)  ( void );
+
 #endif   // __PUB_TOOL_LIBCBASE_H
 
 /*--------------------------------------------------------------------*/