Electroneum
random.h File Reference

Go to the source code of this file.

Functions

void ub_systemseed (unsigned int seed)
 
struct ub_randstate * ub_initstate (unsigned int seed, struct ub_randstate *from)
 
long int ub_random (struct ub_randstate *state)
 
long int ub_random_max (struct ub_randstate *state, long int x)
 
void ub_randfree (struct ub_randstate *state)
 

Detailed Description

Thread safe random functions. Similar to arc4random() with an explicit initialisation routine.

Definition in file random.h.

Function Documentation

◆ ub_initstate()

struct ub_randstate* ub_initstate ( unsigned int  seed,
struct ub_randstate *  from 
)

Initialize a random generator state for use

Parameters
seedseed value to create state contents. (ignored for arc4random).
fromif not NULL, the seed is taken from this random structure. can be used to seed random states via a parent-random-state that is itself seeded with entropy.
Returns
new state or NULL alloc failure.

◆ ub_randfree()

void ub_randfree ( struct ub_randstate *  state)

Delete the random state.

Parameters
stateto delete.

◆ ub_random()

long int ub_random ( struct ub_randstate *  state)

Generate next random number from the state passed along. Thread safe, so random numbers are repeatable.

Parameters
statemust have been initialised with ub_initstate.
Returns
: random 31 bit value.

◆ ub_random_max()

long int ub_random_max ( struct ub_randstate *  state,
long int  x 
)

Generate random number between 0 and x-1. No modulo bias.

Parameters
statemust have been initialised with ub_initstate.
xan upper limit. not (negative or zero). must be smaller than 2**31.
Returns
: random value between 0..x-1. Possibly more than one random number is picked from the random stream to satisfy this.

◆ ub_systemseed()

void ub_systemseed ( unsigned int  seed)

Initialize the system randomness. Obtains entropy from the system before a chroot or privilege makes it unavailable. You do not have to call this, otherwise ub_initstate does so.

Parameters
seedseed value to create state (if no good entropy is found).