Random.h

Go to the documentation of this file.
00001 #ifndef __RANDOM_H__
00002 #define __RANDOM_H__
00003 
00004 #include <stdlib.h>
00005 #include <vector>
00006 
00007 namespace oasys {
00008 
00012 class Random {
00013 public:
00017     static void seed(unsigned int seed) {
00018         srandom(seed);
00019         srand(seed);
00020     }
00021 
00035     static int rand(unsigned int max = RAND_MAX) {
00036         int ret = ::rand();
00037         if (max == RAND_MAX) {
00038             return ret;
00039         }
00040         return (ret % max);
00041     }
00042 };
00043 
00050 class ByteGenerator {
00051 public:
00052     ByteGenerator(unsigned int seed = 0);
00053 
00057     void fill_bytes(void* buf, size_t size);
00058 
00059     static const unsigned int A = 1277;
00060     static const unsigned int M = 131072;
00061     static const unsigned int C = 29574;
00062 
00063 private:
00064     unsigned int cur_;
00065     
00067     void next();
00068 };
00069 
00074 class PermutationArray {
00075 public:
00076     PermutationArray(size_t size);
00077     
00078     unsigned int map(unsigned int i);
00079 
00080 private:
00081     std::vector<unsigned int> array_;
00082     size_t size_;
00083 };
00084 
00085 }; // namespace oasys
00086 
00087 #endif //__RANDOM_H__

Generated on Fri Dec 22 14:48:00 2006 for DTN Reference Implementation by  doxygen 1.5.1