00001 //---------------------------------------------------------------------- 00002 // The Motion Strategy Library (MSL) 00003 //---------------------------------------------------------------------- 00004 // 00005 // Copyright (c) University of Illinois and Steven M. LaValle. 00006 // All Rights Reserved. 00007 // 00008 // Permission to use, copy, and distribute this software and its 00009 // documentation is hereby granted free of charge, provided that 00010 // (1) it is not a component of a commercial product, and 00011 // (2) this notice appears in all copies of the software and 00012 // related documentation. 00013 // 00014 // The University of Illinois and the author make no representations 00015 // about the suitability or fitness of this software for any purpose. 00016 // It is provided "as is" without express or implied warranty. 00017 //---------------------------------------------------------------------- 00018 00019 #ifndef MSL_RANDOM_H 00020 #define MSL_RANDOM_H 00021 00022 00023 class MSLRandomSource { 00024 00025 long table[32]; 00026 long* ptr0; 00027 long* ptr1; 00028 long* ptr2; 00029 long* ptr_end; 00030 unsigned long pat; 00031 int prec; 00032 int low; 00033 int diff; 00034 bool bit_mode; 00035 unsigned long buffer; 00036 static int count; 00037 void init_table(); 00038 00039 public: 00040 00041 unsigned long get_rand31(); 00042 unsigned long get_rand32(); 00043 MSLRandomSource(); 00044 MSLRandomSource(int p); 00045 MSLRandomSource(int low, int high); 00046 unsigned long get() { unsigned long r = get_rand32(); 00047 #if defined(WORD_LENGTH_64) 00048 r = (r << 32) | get_rand32(); 00049 #endif 00050 return r; } 00051 void set_seed(int s); 00052 void set_range(int low, int high); 00053 int set_precision(int p); 00054 int get_precision() { return prec; } 00055 #if defined(__HAS_BUILTIN_BOOL__) 00056 MSLRandomSource& operator>>(char& x); 00057 #endif 00058 MSLRandomSource& operator>>(unsigned char& x); 00059 MSLRandomSource& operator>>(int& x); 00060 MSLRandomSource& operator>>(long& x); 00061 MSLRandomSource& operator>>(unsigned int& x); 00062 MSLRandomSource& operator>>(unsigned long& x); 00063 MSLRandomSource& operator>>(double& x); 00064 MSLRandomSource& operator>>(float& x); 00065 MSLRandomSource& operator>>(bool& b); 00066 int operator()(); 00067 int operator()(int prec); 00068 int operator()(int low, int high); 00069 }; 00070 00071 00072 #endif