X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmath%2Fsg_random.h;h=1fed733d3aa5c683d8903177350ab70a0643c126;hb=1f37095087fa7aa3d210ba134058b86c3bd6d69e;hp=1ff1b1de3162bd65a4dfd052301d11c9c6a7b459;hpb=a53faf45652d31d3f370884b37d21c86eae12115;p=simgear.git diff --git a/simgear/math/sg_random.h b/simgear/math/sg_random.h index 1ff1b1de..1fed733d 100644 --- a/simgear/math/sg_random.h +++ b/simgear/math/sg_random.h @@ -1,8 +1,11 @@ -// sg_random.h -- routines to handle random number generation -// +/** + * \file sg_random.h + * Routines to handle random number generation and hide platform differences. + */ + // Written by Curtis Olson, started July 1997. // -// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com +// Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -14,10 +17,9 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Library General Public License for more details. // -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - Suite 330, -// Boston, MA 02111-1307, USA. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ @@ -31,16 +33,56 @@ extern "C" { #endif -// Seed the random number generater with time() so we don't see the -// same sequence every time -void sg_srandom_time(void); +#define MT_N 624 +#define MT_M 397 + +/** + * Structure to hold MT algorithm state to easily allow independant + * sets of random numbers with different seeds. + */ +struct {unsigned int array[MT_N]; int index; } typedef mt; + +/** + * Initialize a new MT state with a given seed. + */ +void mt_init(mt *mt, unsigned int seed); + +/** + * Generate a new 32-bit random number based on the given MT state. + */ +unsigned int mt_rand32( mt *mt); + +/** + * Generate a new random number between [0.0, 1.0) based + * on the given MT state. + */ +double mt_rand(mt *mt); + +/** + * Seed the random number generater with time() so we don't see the + * same sequence every time. + */ +void sg_srandom_time(); + +/** + * Seed the random number generater with time() in 10 minute intervals + * so we get the same sequence within 10 minutes interval. + * This is useful for synchronizing two display systems. + */ +void sg_srandom_time_10(); -// Seed the random number generater with your own seed so can set up -// repeatable randomization. -void sg_srandom( unsigned int seed ); +/** + * Seed the random number generater with your own seed so can set up + * repeatable randomization. + * @param seed random number generator seed + */ +void sg_srandom(unsigned int seed ); -// return a random number between [0.0, 1.0) -double sg_random(void); +/** + * Return a random number between [0.0, 1.0) + * @return next "random" number in the "random" sequence + */ +double sg_random(); #ifdef __cplusplus