--- parser3/src/classes/math.C 2001/07/18 10:06:04 1.4 +++ parser3/src/classes/math.C 2001/09/26 10:32:25 1.6 @@ -2,10 +2,10 @@ Parser: @b math parser class. Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: math.C,v 1.6 2001/09/26 10:32:25 parser Exp $ */ -static const char *RCSId="$Id: math.C,v 1.4 2001/07/18 10:06:04 parser Exp $"; #include "pa_config_includes.h" #include "pa_common.h" @@ -13,6 +13,10 @@ static const char *RCSId="$Id: math.C,v #include "pa_vmath.h" #include "pa_request.h" +#ifdef WIN32 +# include +#endif + // defines #define PI 3.1415926535 @@ -23,12 +27,14 @@ static const char *RCSId="$Id: math.C,v class MMath : public Methoded { public: MMath(Pool& pool); + void configure_admin(Request& r); + public: // Methoded bool used_directly() { return true; } }; // methods - +static unsigned int randomizer=0; static void _random(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); @@ -39,7 +45,8 @@ static void _random(Request& r, const St &method_name, "bad range [0..%u]", max); - Value& result=*new(pool) VInt(pool, rand()%max); + Value& result=*new(pool) VInt(pool, (int)( + ((double)((randomizer=rand())% RAND_MAX)) / RAND_MAX * (max + 1))); result.set_name(method_name); r.write_no_lang(result); } @@ -108,10 +115,6 @@ MATH2(pow); MMath::MMath(Pool& apool) : Methoded(apool) { set_name(*NEW String(pool(), MATH_CLASS_NAME)); - - - // setting seed - srand(getpid()+time(NULL)); rand(); // ^FUNC(expr) #define ADD1(name) \ @@ -136,6 +139,24 @@ MMath::MMath(Pool& apool) : Methoded(apo } +// in MSVC each thread has it's own pseudo-random sequence +// in win32 apache each thread can handle multiple requests +// so to get proper randoms we remember random generated in one thread +void MMath::configure_admin(Request&) { + // setting seed + srand( + randomizer ^ +#ifdef WIN32 + GetCurrentThreadId() ^ +#else + getpid() ^ +#endif + (unsigned int)time(NULL) + ); + if(!randomizer) + randomizer=rand(); +} + // global variables Methoded *math_base_class;