cctools
random.h File Reference
#include <stdint.h>
#include <stdlib.h>

Go to the source code of this file.

Macros

#define random_int()   ((int) random_int64())
 Get a random int. More...
 
#define random_uint()   ((unsigned) random_int64())
 Get a random unsigned int. More...
 
#define random_int32()   ((int32_t) random_int64())
 Get a random int32_t. More...
 

Functions

void random_init (void)
 Initialize the random number generator. More...
 
int64_t random_int64 (void)
 Get a random int64_t. More...
 
double random_double (void)
 Get a random double from (0, 1) More...
 
void random_array (void *m, size_t l)
 Insert random data into an array. More...
 
void random_hex (char *s, size_t l)
 Insert a random string in hexadecimal. More...
 

Detailed Description

A PRNG library.

Macro Definition Documentation

◆ random_int

#define random_int ( )    ((int) random_int64())

Get a random int.

Returns
a random int.

◆ random_uint

#define random_uint ( )    ((unsigned) random_int64())

Get a random unsigned int.

Returns
a random unsigned int.

◆ random_int32

#define random_int32 ( )    ((int32_t) random_int64())

Get a random int32_t.

Returns
a random int32_t.

Function Documentation

◆ random_init()

void random_init ( void  )

Initialize the random number generator.

Uses system PRNG devices to seed the library PRNG.

◆ random_int64()

int64_t random_int64 ( void  )

Get a random int64_t.

Returns
a random int64_t.

◆ random_double()

double random_double ( void  )

Get a random double from (0, 1)

Returns
a random double from (0, 1)

◆ random_array()

void random_array ( void *  m,
size_t  l 
)

Insert random data into an array.

Parameters
mthe memory to fill.
lthe length of the m.

◆ random_hex()

void random_hex ( char *  s,
size_t  l 
)

Insert a random string in hexadecimal.

Parameters
sthe location in the string.
lthe number of characters to insert. Includes NUL byte!