]> git.mxchange.org Git - simgear.git/blob - simgear/math/sg_random.h
Add project.* to MSVC project files
[simgear.git] / simgear / math / sg_random.h
1 /**
2  * \file sg_random.h
3  * Routines to handle random number generation and hide platform differences.
4  */
5
6 // Written by Curtis Olson, started July 1997.
7 //
8 // Copyright (C) 1997  Curtis L. Olson  - http://www.flightgear.org/~curt
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // Library General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 //
24 // $Id$
25
26
27 #ifndef _SG_RANDOM_H
28 #define _SG_RANDOM_H
29
30
31 #ifdef __cplusplus                                                          
32 extern "C" {                            
33 #endif                                   
34
35
36 #define MT_N 624
37 #define MT_M 397
38
39 /**
40  * Structure to hold MT algorithm state to easily allow independant
41  * sets of random numbers with different seeds.
42  */
43 struct {unsigned int array[MT_N]; int index; } typedef mt;
44
45 /**
46  * Initialize a new MT state with a given seed.
47  */
48 void mt_init(mt *mt, unsigned int seed);
49
50 /**
51  * Generate a new 32-bit random number based on the given MT state.
52  */
53 unsigned int mt_rand32( mt *mt);
54
55 /**
56  * Generate a new random number between [0.0, 1.0) based 
57  * on the given MT state.
58  */
59 double mt_rand(mt *mt);
60  
61 /**
62  * Seed the random number generater with time() so we don't see the
63  * same sequence every time.
64  */
65 void sg_srandom_time();
66
67 /**
68  * Seed the random number generater with time() in 10 minute intervals
69  * so we get the same sequence within 10 minutes interval.
70  * This is useful for synchronizing two display systems.
71  */
72 void sg_srandom_time_10();
73
74 /**
75  * Seed the random number generater with your own seed so can set up
76  * repeatable randomization.
77  * @param seed random number generator seed
78  */
79 void sg_srandom(unsigned int seed );
80
81 /**
82  * Return a random number between [0.0, 1.0)
83  * @return next "random" number in the "random" sequence
84  */
85 double sg_random();
86
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92
93 #endif // _SG_RANDOM_H
94
95