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