Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_rand.h File Reference
#include <string.h>
#include "vl_memory.h"
#include "vl_numtypes.h"
+ Include dependency graph for vl_rand.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define VL_H_RANDOM_SPLIT(randPtr, resultPtr)   (vlRandSplitBytes((randPtr), (resultPtr)))
 
#define vlRandFx4(randPtr, resultPtr)
 Generates four random floats.
 

Functions

VL_API vl_rand vlRandInit (void)
 Initializes a random state (aka, seed) based on the current time.
 
VL_API vl_rand vlRandNext (vl_rand *rand)
 Returns the "next" 64-bit integer.
 
VL_API void vlRandFill (vl_rand *rand, void *mem, vl_ularge_t len)
 Fills the specified region of memory with random bytes.
 
VL_API vl_float32_t vlRandF (vl_rand *randPtr)
 Generate a random float.
 
VL_API void vlRandFx2 (vl_rand *randPtr, vl_float32_t *resultPtr)
 Generates two random floats.
 
VL_API vl_float64_t vlRandD (vl_rand *randPtr)
 Generate a random double.
 

Macro Definition Documentation

◆ VL_H_RANDOM_SPLIT

#define VL_H_RANDOM_SPLIT (   randPtr,
  resultPtr 
)    (vlRandSplitBytes((randPtr), (resultPtr)))

◆ vlRandFx4

#define vlRandFx4 (   randPtr,
  resultPtr 
)
Value:
vlRandFx2(randPtr, (vl_float32_t*)(resultPtr)); \
vlRandFx2(randPtr, ((vl_float32_t*)(resultPtr)) + 2)
VL_F32_T vl_float32_t
32-bit floating point number type.
Definition vl_numtypes.h:173
VL_API void vlRandFx2(vl_rand *randPtr, vl_float32_t *resultPtr)
Generates two random floats.
Definition vl_rand.c:175

Generates four random floats.

Range of returned floats is in range of 0...1.

Parameters
randPtrpointer to random state
resultPtrwhere the result will be stored.
Complexity of O(1) constant.
Returns
void

Function Documentation

◆ vlRandD()

VL_API vl_float64_t vlRandD ( vl_rand *  randPtr)

Generate a random double.

Range of returned value is in 0...1.

Parameters
randPtrpointer to random state
Complexity of O(1) constant.
Returns
random double.

◆ vlRandF()

VL_API vl_float32_t vlRandF ( vl_rand *  randPtr)

Generate a random float.

Range of returned value is in 0...1.

Parameters
randPtrpointer to random state
Complexity of O(1) constant.
Returns
random float
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ vlRandFill()

VL_API void vlRandFill ( vl_rand *  rand,
void *  mem,
vl_ularge_t  len 
)

Fills the specified region of memory with random bytes.

This function operates on blocks of 8 bytes at a time, until it fills in the last few remaining bytes.

Parameters
randrand state
memdestination
lentotal number of bytes to fill.
Complexity of O(n) linear.

◆ vlRandFx2()

VL_API void vlRandFx2 ( vl_rand *  randPtr,
vl_float32_t resultPtr 
)

Generates two random floats.

Range of returned floats is in range of 0...1.

Parameters
randPtrpointer to random state
resultPtrwhere the result will be stored
Complexity of O(1) constant.
+ Here is the call graph for this function:

◆ vlRandInit()

VL_API vl_rand vlRandInit ( void  )

Initializes a random state (aka, seed) based on the current time.

This function can be skipped entirely, assuming another seed integer can be provided.

Complexity of O(1) constant.
Returns
random state/seed.
+ Here is the call graph for this function:

◆ vlRandNext()

VL_API vl_rand vlRandNext ( vl_rand *  rand)

Returns the "next" 64-bit integer.

This function has a side effect of updating the random state.

Complexity of O(1) constant.
Parameters
randpointer to random state
Returns
unsigned 64-bit integer
+ Here is the caller graph for this function: