Main Page | Alphabetical List | Class List | File List | Class Members | File Members

rand.h

Go to the documentation of this file.
00001 #ifndef _RAND_H_
00002 #define _RAND_H_
00003 
00008 #include <nlibc.h>
00009 
00010 #ifdef __HAS_MAIN
00011 static unsigned __rand_next;
00012 #endif // __HAS_MAIN
00013 
00014 #if RAND_MAX != INT_MAX
00015 #error "Assume RAND_MAX equal to INT_MAX"
00016 #endif
00017 
00018 #if !defined(__cflow_processed) || defined(_uses_rand_r_rand_h)
00019 inline unsigned rand_r(unsigned *seed) {
00020   const unsigned ia = 0x27bb2ee687b0b0fdULL;
00021   const unsigned ic = 0x00000000b504f32dULL;
00022 
00023   *seed = (*seed) * ia + ic;
00024 
00025   return (*seed);
00026 }
00027 #endif // _uses_rand_r_rand_h
00028 
00029 //------------------------------------------------------------------------------
00097 #if !defined(__cflow_processed) || defined(_uses_rand_rand_h)
00098 inline int rand(void)
00099 {
00100   register int r = (int) (rand_r(&__rand_next));
00101 
00102   where (r < 0)
00103     r = -r;
00104   
00105   return r;
00106 }
00107 #endif // _uses_rand_rand_h
00108 
00109 
00110 #if !defined(__cflow_processed) || defined(_uses_vrand_rand_h)
00111 inline vector int vrand(void)
00112 {
00113 #ifdef __cflow_processed
00114   #error "Not yet implemented"
00115 #endif
00116   return 0;
00117 }
00118 #endif // _uses_srand_rand_h
00119 
00120 
00121 #if !defined(__cflow_processed) || defined(_uses_srand_rand_h)
00122 inline void srand(unsigned int seed)
00123 {
00124         __rand_next = seed;
00125 }
00126 #endif // _uses_srand_rand_h
00127 
00128 
00129 #if !defined(__cflow_processed) || defined(_uses_vsrand_rand_h)
00130 inline void vsrand(vector unsigned seed)
00131 {
00132 #ifdef __cflow_processed
00133   #error "Not yet implemented"
00134 #endif
00135 }
00136 #endif // _uses_srand_rand_h
00137 
00138 
00139 #endif // _RAND_H_

Generated on Fri Jul 14 10:51:31 2006 for nlibc by doxygen 1.3.5