00001 /* 00002 * lib/numerics/rng/libc.cc 00003 * 00004 * Interface implementation for LIBC random() PRNG. 00005 * 00006 * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 00007 * 00008 * This file may be distributed and/or modified under the terms of the 00009 * GNU General Public License version 2 as published by the Free Software 00010 * Foundation. (See COPYING.GPL for details.) 00011 * 00012 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00013 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00014 * 00015 */ 00016 00017 #include "libc.h" 00018 00019 namespace NUM // numerics 00020 { 00021 00022 void RandomNumberGenerator_LibCRandom::seed(uint seed,int statelen) 00023 { 00024 statebuf=REALLOC(statebuf,statelen); 00025 initstate_r(seed,statebuf,statelen,&rdata); 00026 setstate_r(statebuf,&rdata); 00027 } 00028 00029 00030 static char _StartupCheck() 00031 { 00032 // Make sure random_r returns random number in "full 31 bit spectrum". 00033 CritAssert(RAND_MAX==0x7fffffff); // critical (startup check) 00034 } 00035 00036 static char _startup_check=_StartupCheck(); 00037 00038 } // end of namespace NUM