00001 #include "random.h"
00002 
00003 #include <stdlib.h>
00004 
00005 
00006 
00007 
00008 Random::Random(int seedTime)
00009 {
00010     
00011   
00012 }
00013 
00014 Random::~Random()
00015 {
00016     
00017 }
00018 
00019 
00020 
00021 
00022 int Random::randint()
00023 {
00024     return rand();
00025 }
00026 
00027 
00028 int Random::randint(int max)
00029 {
00030     return (int) (max*rand()/(RAND_MAX+1.0));
00031 }
00032 
00033 
00034 int Random::randint(int min, int max)
00035 {
00036     if (min>max)
00037     {
00038         return max + (int) ((min-max+1)*rand()/(RAND_MAX+1.0));
00039     }
00040     else
00041     {
00042         return min + (int) ((max-min+1)*rand()/(RAND_MAX+1.0));
00043     }
00044 }
00045 
00046 
00047 float Random::randfloat()
00048 {
00049     return rand()/((float)(RAND_MAX)+1);
00050 }
00051 
00052 
00053 float Random::randfloat(float max)
00054 {
00055     return randfloat()*max;
00056 }
00057 
00058 
00059 float Random::randfloat(float min, float max)
00060 {
00061     if (min>max)
00062     {
00063         return randfloat()*(min-max)+max;
00064     }
00065     else
00066     {
00067         return randfloat()*(max-min)+min;
00068     }
00069 }
00070 
00071 
00072 double Random::randdouble()
00073 {
00074     return rand()/((double)(RAND_MAX)+1);
00075 }
00076 
00077 
00078 double Random::randdouble(double max)
00079 {
00080     return randdouble()*max;
00081 }
00082 
00083 
00084 double Random::randdouble(double min, double max)
00085 {
00086     if (min>max)
00087     {
00088         return randdouble()*(min-max)+max;
00089     }
00090     else
00091     {
00092         return randdouble()*(max-min)+min;
00093     }
00094 }
00095