Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-19 08:08:31

0001 // Public random number operations.
0002 
0003 #ifndef _CL_RANDOM_H
0004 #define _CL_RANDOM_H
0005 
0006 #include "cln/types.h"
0007 #include "cln/modules.h"
0008 
0009 namespace cln {
0010 
0011 class random_state {
0012 public:
0013     struct { uint32 hi; uint32 lo; } seed;
0014 // Constructor:
0015     random_state ();
0016 };
0017 
0018 // random32(randomstate) liefert eine neue Zufallszahl.
0019 // > randomstate: ein Random-State, wird verändert
0020 // < ergebnis: eine 32-Bit-Zufallszahl
0021 extern uint32 random32 (random_state& randomstate);
0022 
0023 #if defined(HAVE_FAST_LONGLONG)
0024 // random64(randomstate) liefert eine neue Zufallszahl.
0025 // > randomstate: ein Random-State, wird verändert
0026 // < ergebnis: eine 64-Bit-Zufallszahl
0027 inline uint64 random64 (random_state& randomstate)
0028 {
0029     return ((uint64)random32(randomstate) << 32)
0030            | (uint64)random32(randomstate);
0031 }
0032 #endif
0033 
0034 // Ein globaler Zufallszahlengenerator.
0035 extern random_state default_random_state;
0036 class cl_random_def_init_helper
0037 {
0038     static int count;
0039 public:
0040     cl_random_def_init_helper();
0041     ~cl_random_def_init_helper();
0042 };
0043 static cl_random_def_init_helper cl_random_def_init_helper_instance;
0044 
0045 // Das ist der Default-Generator.
0046 inline uint32 random32 (void)
0047     { return random32(default_random_state); }
0048 #if defined(HAVE_FAST_LONGLONG)
0049 inline uint64 random64 (void)
0050     { return random64(default_random_state); }
0051 #endif
0052 
0053 }  // namespace cln
0054 
0055 #endif /* _CL_RANDOM_H */