|
|
random.cGo to the documentation of this file.00001 #include "random.h" 00002 00003 #include <sys/types.h> 00004 #include <time.h> 00005 #include <stdlib.h> 00006 #include <math.h> 00007 00018 void randomReset() 00019 { 00020 srand((unsigned int)time(NULL)); 00021 } 00022 00023 void randomSet(unsigned int seed) 00024 { 00025 srand(seed); 00026 } 00027 00028 double randomDouble() 00029 { 00030 return((double)rand()/(double)RAND_MAX); 00031 } 00032 00033 double randomInInterval(Tinterval *t) 00034 { 00035 double a,b; 00036 00037 a=LowerLimit(t); 00038 b=UpperLimit(t); 00039 00040 return(a+randomDouble()*(b-a)); 00041 } 00042 00043 unsigned int randomMax(unsigned int m) 00044 { 00045 return((unsigned int)floor(randomDouble()*(m+1))); /* in [0,m+1) -> all values in 0,m have same chances */ 00046 } |