| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #ifndef VL_RANDOM_H |
| | #define VL_RANDOM_H |
| |
|
| | #include "host.h" |
| |
|
| | |
| | typedef struct _VlRand { |
| | vl_uint32 mt [624] ; |
| | vl_uint32 mti ; |
| | } VlRand ; |
| |
|
| | |
| | |
| | |
| | VL_EXPORT void vl_rand_init (VlRand * self) ; |
| | VL_EXPORT void vl_rand_seed (VlRand * self, vl_uint32 s) ; |
| | VL_EXPORT void vl_rand_seed_by_array (VlRand * self, |
| | vl_uint32 const key [], |
| | vl_size keySize) ; |
| | |
| |
|
| | |
| | |
| | |
| | VL_INLINE vl_uint64 vl_rand_uint64 (VlRand * self) ; |
| | VL_INLINE vl_int64 vl_rand_int63 (VlRand * self) ; |
| | VL_EXPORT vl_uint32 vl_rand_uint32 (VlRand * self) ; |
| | VL_INLINE vl_int32 vl_rand_int31 (VlRand * self) ; |
| | VL_INLINE double vl_rand_real1 (VlRand * self) ; |
| | VL_INLINE double vl_rand_real2 (VlRand * self) ; |
| | VL_INLINE double vl_rand_real3 (VlRand * self) ; |
| | VL_INLINE double vl_rand_res53 (VlRand * self) ; |
| | VL_INLINE vl_uindex vl_rand_uindex (VlRand * self, vl_uindex range) ; |
| | |
| |
|
| | VL_EXPORT void vl_rand_permute_indexes (VlRand * self, vl_index* array, vl_size size) ; |
| |
|
| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | VL_INLINE vl_uindex |
| | vl_rand_uindex (VlRand * self, vl_uindex range) |
| | { |
| | if (range <= 0xffffffff) { |
| | |
| | return (vl_rand_uint32 (self) % (vl_uint32)range) ; |
| | } else { |
| | |
| | return (vl_rand_uint64 (self) % range) ; |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | VL_INLINE vl_uint64 |
| | vl_rand_uint64 (VlRand * self) |
| | { |
| | vl_uint64 a = vl_rand_uint32 (self) ; |
| | vl_uint64 b = vl_rand_uint32 (self) ; |
| | return (a << 32) | b ; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | VL_INLINE vl_int64 |
| | vl_rand_int63 (VlRand * self) |
| | { |
| | return (vl_int64)(vl_rand_uint64 (self) >> 1) ; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | VL_INLINE vl_int32 |
| | vl_rand_int31 (VlRand * self) |
| | { |
| | return (vl_int32)(vl_rand_uint32 (self) >> 1) ; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | VL_INLINE double |
| | vl_rand_real1 (VlRand * self) |
| | { |
| | return vl_rand_uint32(self)*(1.0/4294967295.0); |
| | |
| | } |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | VL_INLINE double |
| | vl_rand_real2 (VlRand * self) |
| | { |
| | return vl_rand_uint32(self)*(1.0/4294967296.0); |
| | |
| | } |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | VL_INLINE double |
| | vl_rand_real3 (VlRand * self) |
| | { |
| | return (((double)vl_rand_uint32(self)) + 0.5)*(1.0/4294967296.0); |
| | |
| | } |
| |
|
| | |
| | |
| | |
| | |
| |
|
| | VL_INLINE double |
| | vl_rand_res53 (VlRand * self) |
| | { |
| | vl_uint32 |
| | a = vl_rand_uint32(self) >> 5, |
| | b = vl_rand_uint32(self) >> 6 ; |
| | return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0) ; |
| | } |
| |
|
| | |
| | #endif |
| |
|