Add a simple random number generator to m_libcbase so we don't have
to use the one from glibc.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4130 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_libcbase.c b/coregrind/m_libcbase.c
index 7369cb3..f8c4275 100644
--- a/coregrind/m_libcbase.c
+++ b/coregrind/m_libcbase.c
@@ -471,6 +471,21 @@
#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 ---*/
/*--------------------------------------------------------------------*/
diff --git a/coregrind/m_skiplist.c b/coregrind/m_skiplist.c
index 796b1d3..f9ca188 100644
--- a/coregrind/m_skiplist.c
+++ b/coregrind/m_skiplist.c
@@ -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 @@
{
UInt ret = 0;
- while((ret < SK_MAXHEIGHT - 1) && (random() & 1))
+ while((ret < SK_MAXHEIGHT - 1) && (VG_(random)() & 1))
ret++;
return ret;
diff --git a/include/pub_tool_libcbase.h b/include/pub_tool_libcbase.h
index fb59b39..d1f7f5c 100644
--- a/include/pub_tool_libcbase.h
+++ b/include/pub_tool_libcbase.h
@@ -114,6 +114,11 @@
/* 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
/*--------------------------------------------------------------------*/