00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __RANDOM_H__
00018 #define __RANDOM_H__
00019
00020 #include <stdlib.h>
00021 #include <vector>
00022
00023 namespace oasys {
00024
00028 class Random {
00029 public:
00033 static void seed(unsigned int seed) {
00034 srandom(seed);
00035 srand(seed);
00036 }
00037
00051 static int rand(unsigned int max = RAND_MAX) {
00052 int ret = ::rand();
00053 if (max == RAND_MAX) {
00054 return ret;
00055 }
00056 return (ret % max);
00057 }
00058 };
00059
00066 class ByteGenerator {
00067 public:
00068 ByteGenerator(unsigned int seed = 0);
00069
00073 void fill_bytes(void* buf, size_t size);
00074
00075 static const unsigned int A = 1277;
00076 static const unsigned int M = 131072;
00077 static const unsigned int C = 29574;
00078
00079 private:
00080 unsigned int cur_;
00081
00083 void next();
00084 };
00085
00090 class PermutationArray {
00091 public:
00092 PermutationArray(size_t size);
00093
00094 unsigned int map(unsigned int i);
00095
00096 private:
00097 std::vector<unsigned int> array_;
00098 size_t size_;
00099 };
00100
00101 };
00102
00103 #endif //__RANDOM_H__