Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_rand.h
Go to the documentation of this file.
1#ifndef VL_RAND_H
2#define VL_RAND_H
3
4#include "vl_numtypes.h"
5#include "vl_memory.h"
6
7#ifndef VL_H_RANDOM_SPLIT
18#define VL_H_RANDOM_SPLIT(randPtr, resultPtr) (*((vl_ularge_t*)(resultPtr)) = vlRandNext(randPtr))
19#endif
20
29
39
50
62void vlRandFill(vl_rand* rand, void* mem, vl_ularge_t len);
63
64#ifdef VL_U8_T
73#define vlRandUInt8(randPtr) (vl_uint8_t) (vlRandNext(randPtr))
74
75#ifdef VL_U64_T
83#define vlRandUInt8x8(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr)
84#elif defined VL_U32_T
92#define vlRandUInt8x8(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr); \
93 VL_H_RANDOM_SPLIT(randPtr, ((VL_U8_T*)(resultPtr)) + 4)
94#endif
95#endif
96
97#ifdef VL_U16_T
107#define vlRandUInt16(randPtr) (vl_uint16_t) (vlRandNext(randPtr))
108
109#ifdef VL_U64_T
119#define vlRandUInt16x4(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr)
120#elif defined VL_U32_T
130#define vlRandUInt16x4(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr); \
131 VL_H_RANDOM_SPLIT(randPtr, ((VL_U16_T*)(resultPtr)) + 2)
132#endif
133#endif
134
135#ifdef VL_U32_T
145#define vlRandUInt32(randPtr) (vl_uint32_t) (vlRandNext(randPtr))
146
147#ifdef VL_U64_T
157#define vlRandUInt32x2(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr)
158#else
168#define vlRandUInt32x2(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr); \
169 VL_H_RANDOM_SPLIT(randPtr, ((VL_U32_T*)(resultPtr) + 1))
170#endif
171#endif
172
173#ifdef VL_U64_T
174
184#define vlRandUInt64(randPtr) (vl_uint64_t) (vlRandNext(randPtr))
185#endif
186
187#ifdef VL_I8_T
197vl_int8_t vlRandInt8 (vl_rand* rand);
198
199#ifdef VL_U64_T
209#define vlRandInt8x8(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr)
210#elif defined VL_U32_T
220#define vlRandInt8x8(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr); \
221 VL_H_RANDOM_SPLIT(randPtr, ((VL_I8_T*)(resultPtr) + 4)
222#endif
223#endif
224
225#ifdef VL_I16_T
234vl_int16_t vlRandInt16 (vl_rand* rand);
235
236#ifdef VL_U64_T
246#define vlRandInt16x4(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr)
247#elif defined VL_U32_T
248
258#define vlRandInt16x4(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr);\
259 VL_H_RANDOM_SPLIT(randPtr, (VL_I16_T)(resultPtr) + 2)
260#endif
261#endif
262
263#ifdef VL_I32_T
272vl_int32_t vlRandInt32 (vl_rand* rand);
273
274#ifdef VL_I64_T
284#define vlRandInt32x2(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr)
285#elif defined VL_I32_T
295#define vlRandInt32x2(randPtr, resultPtr) VL_H_RANDOM_SPLIT(randPtr, resultPtr);\
296 VL_H_RANDOM_SPLIT(randPtr, ((VL_I32_T*)(resultPtr)) + 1)
297#endif
298#endif
299
300#ifdef VL_I64_T
310vl_int64_t vlRandInt64 (vl_rand* rand);
311#endif
312
322vl_float32_t vlRandF (vl_rand* randPtr);
323
333void vlRandFx2 (vl_rand* randPtr, vl_float32_t* resultPtr);
334
345#define vlRandFx4(randPtr, resultPtr) vlRandFx2(randPtr, (vl_float32_t*)(resultPtr));\
346 vlRandFx2(randPtr, ((vl_float32_t*)(resultPtr)) + 2)
347
357vl_float64_t vlRandD (vl_rand* randPtr);
358
359#endif //VL_RAND_H
VL_F32_T vl_float32_t
32-bit floating point number type.
Definition vl_numtypes.h:111
VL_ULARGE_T vl_ularge_t
Largest available unsigned integer type.
Definition vl_numtypes.h:74
vl_float32_t vlRandF(vl_rand *randPtr)
Generate a random float.
Definition vl_rand.c:120
vl_float64_t vlRandD(vl_rand *randPtr)
Generate a random double.
vl_rand vlRandNext(vl_rand *rand)
Returns the "next" 64-bit integer.
Definition vl_rand.c:50
vl_rand vlRandInit()
Initializes a random state (aka, seed) based on the current time.
Definition vl_rand.c:44
vl_ularge_t vl_rand
Random state type.
Definition vl_rand.h:28
void vlRandFill(vl_rand *rand, void *mem, vl_ularge_t len)
Fills the specified region of memory with random bytes.
void vlRandFx2(vl_rand *randPtr, vl_float32_t *resultPtr)
Generates two random floats.
Definition vl_rand.c:126