summaryrefslogtreecommitdiffstats
path: root/libg++/libstdc++/stl/random.cc
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2008-06-01 00:03:21 +0000
committerpeter <peter@FreeBSD.org>2008-06-01 00:03:21 +0000
commita2be5f0c15218b0177d73b17d9bcb7589965d685 (patch)
treec9f0cd9c22378356a1716d32e13e70bc90f98b9c /libg++/libstdc++/stl/random.cc
parent9e0f3cc19c9df1594c9cc36cfd8fddc83c52ad12 (diff)
downloadFreeBSD-src-a2be5f0c15218b0177d73b17d9bcb7589965d685.zip
FreeBSD-src-a2be5f0c15218b0177d73b17d9bcb7589965d685.tar.gz
Reorganize the gcc vendor import work area. This flattens out a bunch
of unnecessary path components that are relics of cvs2svn. (These are directory moves)
Diffstat (limited to 'libg++/libstdc++/stl/random.cc')
-rw-r--r--libg++/libstdc++/stl/random.cc60
1 files changed, 60 insertions, 0 deletions
diff --git a/libg++/libstdc++/stl/random.cc b/libg++/libstdc++/stl/random.cc
new file mode 100644
index 0000000..e79872c
--- /dev/null
+++ b/libg++/libstdc++/stl/random.cc
@@ -0,0 +1,60 @@
+/*
+ *
+ * Copyright (c) 1994
+ * Hewlett-Packard Company
+ *
+ * Permission to use, copy, modify, distribute and sell this software
+ * and its documentation for any purpose is hereby granted without fee,
+ * provided that the above copyright notice appear in all copies and
+ * that both that copyright notice and this permission notice appear
+ * in supporting documentation. Hewlett-Packard Company makes no
+ * representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ */
+
+#include <stddef.h>
+
+#define __SEED 161803398
+
+class __random_generator {
+protected:
+ unsigned long table[55];
+ size_t index1;
+ size_t index2;
+public:
+ unsigned long operator()(unsigned long limit) {
+ index1 = (index1 + 1) % 55;
+ index2 = (index2 + 1) % 55;
+ table[index1] = table[index1] - table[index2];
+ return table[index1] % limit;
+ }
+ void seed(unsigned long j);
+ __random_generator(unsigned long j) { seed(j); }
+};
+
+void __random_generator::seed(unsigned long j) {
+ unsigned long k = 1;
+ table[54] = j;
+ for (size_t i = 0; i < 54; i++) {
+ size_t ii = 21 * i % 55;
+ table[ii] = k;
+ k = j - k;
+ j = table[ii];
+ }
+ for (int loop = 0; loop < 4; loop++) {
+ for (size_t i = 0; i < 55; i++)
+ table[i] = table[i] - table[(1 + i + 30) % 55];
+ }
+ index1 = 0;
+ index2 = 31;
+}
+
+static __random_generator rd(__SEED);
+
+unsigned long __long_random(unsigned long limit) {
+ return rd(limit);
+}
+
+
+
OpenPOWER on IntegriCloud