--- methods.cxx 2011-01-18 13:57:09.000000000 +0300 +++ methods.cxx.fixed 2011-02-24 22:09:40.000000000 +0300 @@ -3335,43 +3335,59 @@ { String aFmt( rPar.Get(2)->GetString() ); rPar.Get(1)->Format( aResult, &aFmt ); } rPar.Get(0)->PutString( aResult ); } } +static double single_rnd = -1.; +static double last_rnd = -1.; + +#define NEXT_RND ( last_rnd = (double)rand() / ((double)RAND_MAX + (double)1.) ) + RTLFUNC(Randomize) { (void)pBasic; (void)bWrite; if ( rPar.Count() > 2 ) StarBASIC::Error( SbERR_BAD_ARGUMENT ); INT16 nSeed; if( rPar.Count() == 2 ) nSeed = (INT16)rPar.Get(1)->GetInteger(); else nSeed = (INT16)rand(); srand( nSeed ); + single_rnd = NEXT_RND; } RTLFUNC(Rnd) { (void)pBasic; (void)bWrite; if ( rPar.Count() > 2 ) StarBASIC::Error( SbERR_BAD_ARGUMENT ); else { - double nRand = (double)rand(); - nRand = ( nRand / (double)RAND_MAX ); - rPar.Get(0)->PutDouble( nRand ); + if ( single_rnd < 0 ) + single_rnd = NEXT_RND; + + if ( rPar.Count() == 2 ) + { + INT16 param = (INT16)rPar.Get(1)->GetInteger(); + if ( param < 0 ) + rPar.Get(0)->PutDouble( single_rnd ); + else + rPar.Get(0)->PutDouble( param > 0 ? NEXT_RND : last_rnd ); + } + else + rPar.Get(0)->PutDouble( NEXT_RND ); } } // // Syntax: Shell("Path",[ Window-Style,[ "Params", [ bSync = FALSE ]]]) // // WindowStyles (VBA-kompatibel):