]> www.ginac.de Git - cln.git/blob - include/cl_random.h
- Added lots of @cindex to produce an index.
[cln.git] / include / cl_random.h
1 // Public random number operations.
2
3 #ifndef _CL_RANDOM_H
4 #define _CL_RANDOM_H
5
6 #include "cl_types.h"
7 #include "cl_modules.h"
8
9 class cl_random_state {
10 public:
11         struct { uint32 hi; uint32 lo; } seed;
12 // Constructor:
13         cl_random_state ();
14 };
15
16 // random32(randomstate) liefert eine neue Zufallszahl.
17 // > randomstate: ein Random-State, wird verändert
18 // < ergebnis: eine 32-Bit-Zufallszahl
19 extern uint32 random32 (cl_random_state& randomstate);
20
21 #if defined(HAVE_FAST_LONGLONG)
22 // random64(randomstate) liefert eine neue Zufallszahl.
23 // > randomstate: ein Random-State, wird verändert
24 // < ergebnis: eine 64-Bit-Zufallszahl
25 inline uint64 random64 (cl_random_state& randomstate)
26 {
27         return ((uint64)random32(randomstate) << 32)
28                | (uint64)random32(randomstate);
29 }
30 #endif
31
32 // Ein globaler Zufallszahlengenerator.
33 extern cl_random_state cl_default_random_state;
34 CL_REQUIRE(cl_random_def)
35 // Das ist der Default-Generator.
36 inline uint32 random32 (void)
37         { return random32(cl_default_random_state); }
38 #if defined(HAVE_FAST_LONGLONG)
39 inline uint64 random64 (void)
40         { return random64(cl_default_random_state); }
41 #endif
42
43 #endif /* _CL_RANDOM_H */