File indexing completed on 2026-05-19 08:08:31
0001
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
0015 random_state ();
0016 };
0017
0018
0019
0020
0021 extern uint32 random32 (random_state& randomstate);
0022
0023 #if defined(HAVE_FAST_LONGLONG)
0024
0025
0026
0027 inline uint64 random64 (random_state& randomstate)
0028 {
0029 return ((uint64)random32(randomstate) << 32)
0030 | (uint64)random32(randomstate);
0031 }
0032 #endif
0033
0034
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
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 }
0054
0055 #endif