|
From: <sv...@va...> - 2005-07-08 04:09:39
|
Author: njn
Date: 2005-07-08 05:08:59 +0100 (Fri, 08 Jul 2005)
New Revision: 4130
Log:
Add a simple random number generator to m_libcbase so we don't have
to use the one from glibc.
Modified:
trunk/coregrind/m_libcbase.c
trunk/coregrind/m_skiplist.c
trunk/include/pub_tool_libcbase.h
Modified: trunk/coregrind/m_libcbase.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_libcbase.c 2005-07-08 01:29:33 UTC (rev 4129)
+++ trunk/coregrind/m_libcbase.c 2005-07-08 04:08:59 UTC (rev 4130)
@@ -471,6 +471,21 @@
#undef SORT
}
=20
+static UInt seed =3D 0;
+
+void VG_(srandom)(UInt s)
+{
+ seed =3D s;
+}
+
+// This random number generator is based on the one suggested in Kernigh=
an
+// and Ritchie's "The C Programming Language".
+UInt VG_(random)(void)
+{
+ seed =3D (1103515245*seed + 12345);
+ return seed;
+}
+
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
Modified: trunk/coregrind/m_skiplist.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_skiplist.c 2005-07-08 01:29:33 UTC (rev 4129)
+++ trunk/coregrind/m_skiplist.c 2005-07-08 04:08:59 UTC (rev 4130)
@@ -93,8 +93,6 @@
#include "pub_core_mallocfree.h"
#include "pub_core_skiplist.h"
=20
-#include <stdlib.h>
-
#define SKIPLIST_DEBUG 0
=20
#define SK_MAXHEIGHT 20 /* 2^20 elements */
@@ -121,7 +119,7 @@
{
UInt ret =3D 0;
=20
- while((ret < SK_MAXHEIGHT - 1) && (random() & 1))
+ while((ret < SK_MAXHEIGHT - 1) && (VG_(random)() & 1))
ret++;
=20
return ret;
Modified: trunk/include/pub_tool_libcbase.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/include/pub_tool_libcbase.h 2005-07-08 01:29:33 UTC (rev 4129)
+++ trunk/include/pub_tool_libcbase.h 2005-07-08 04:08:59 UTC (rev 4130)
@@ -114,6 +114,11 @@
/* Returns the base-2 logarithm of x. */
extern Int VG_(log2) ( Int x );
=20
+// 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
=20
/*--------------------------------------------------------------------*/
|