Veritable Lasagna
An Allocator & Data Structure Library for C.
Loading...
Searching...
No Matches
vl_rand.c File Reference
#include "vl_rand.h"
#include <time.h>
#include <limits.h>
+ Include dependency graph for vl_rand.c:

Macros

#define VL_IEEE754_FLOAT32_LOW23   0x007FFFFFu
 
#define VL_IEEE754_FLOAT32_ONE   0x3F800000u
 
#define VL_IEEE754_FLOAT32_LOW23_DW   0x007FFFFF007FFFFFull
 
#define VL_IEEE754_FLOAT32_ONE_DW   0x3F8000003F800000ull
 
#define VL_IEEE754_FLOAT64_LOW52   0x000FFFFFFFFFFFFFull
 
#define VL_IEEE754_FLOAT64_ONE   0x3FF0000000000000ull
 

Functions

vl_rand vlRandInit ()
 Initializes a random state (aka, seed) based on the current time.
 
vl_rand vlRandNext (vl_rand *rand)
 Returns the "next" 64-bit integer.
 
void vlRandFill (vl_rand *rand, void *mem, vl_memsize_t len)
 
vl_float32_t vlRandF (vl_rand *rand)
 Generate a random float.
 
void vlRandFx2 (vl_rand *rand, vl_float32_t *result)
 Generates two random floats.
 

Macro Definition Documentation

◆ VL_IEEE754_FLOAT32_LOW23

#define VL_IEEE754_FLOAT32_LOW23   0x007FFFFFu

◆ VL_IEEE754_FLOAT32_LOW23_DW

#define VL_IEEE754_FLOAT32_LOW23_DW   0x007FFFFF007FFFFFull

◆ VL_IEEE754_FLOAT32_ONE

#define VL_IEEE754_FLOAT32_ONE   0x3F800000u

◆ VL_IEEE754_FLOAT32_ONE_DW

#define VL_IEEE754_FLOAT32_ONE_DW   0x3F8000003F800000ull

◆ VL_IEEE754_FLOAT64_LOW52

#define VL_IEEE754_FLOAT64_LOW52   0x000FFFFFFFFFFFFFull

◆ VL_IEEE754_FLOAT64_ONE

#define VL_IEEE754_FLOAT64_ONE   0x3FF0000000000000ull

Function Documentation

◆ vlRandF()

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()

void vlRandFill ( vl_rand * rand,
void * mem,
vl_memsize_t len )
+ Here is the call graph for this function:

◆ vlRandFx2()

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_rand vlRandInit ( )

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_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: