Random float and integer ranges by IanM23rd Aug 2004 7:42
|
---|
Summary Provides a different random number system to the built-in version. This allows you to get floating point random numbers, and float/integer random numbers within a specified range. Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com global FloatRnd_Seed as integer function IntRndRange(Lower as integer, Upper as integer) local Result as integer Result = FloatRndRange(Lower, Upper+1) endfunction Result function FloatRndRange(Lower as float, Upper as float) local Result as double float Result=(FloatRnd()*(Upper-Lower))+Lower endfunction Result function FloatRnd() local Result as double float FloatRnd_Seed=(( FloatRnd_Seed * 1103515245 ) + 12345) mod 0x7fffffff Result=abs(FloatRnd_Seed / (0x7fffffff+0.0)) endfunction Result function FloatRndSeed(Seed as integer) FloatRnd_Seed=Seed endfunction |