libcoap  4.3.0
Pseudo Random Numbers

API functions for gerating pseudo random numbers. More...

Typedefs

typedef int(* coap_rand_func_t) (void *out, size_t len)
 Data type for random number generator function. More...
 

Functions

void coap_set_prng (coap_rand_func_t rng)
 Replaces the current random number generation function with the default function rng. More...
 
void coap_prng_init (unsigned int seed)
 Seeds the default random number generation function with the given seed. More...
 
int coap_prng (void *buf, size_t len)
 Fills buf with len random bytes using the default pseudo random number generator. More...
 

Detailed Description

API functions for gerating pseudo random numbers.

Typedef Documentation

◆ coap_rand_func_t

typedef int(* coap_rand_func_t) (void *out, size_t len)

Data type for random number generator function.

The function must fill len bytes of random data into the buffer starting at out. On success, the function should return 1, zero otherwise.

Definition at line 77 of file coap_prng.h.

Function Documentation

◆ coap_prng()

int coap_prng ( void *  buf,
size_t  len 
)

Fills buf with len random bytes using the default pseudo random number generator.

The default PRNG can be changed with coap_set_prng(). This function returns 1 when len random bytes have been written to buf, zero otherwise.

Parameters
bufThe buffer to fill with random bytes.
lenThe number of random bytes to write into buf.
Returns
1 on success, 0 otherwise.

Definition at line 87 of file coap_prng.c.

+ Here is the caller graph for this function:

◆ coap_prng_init()

void coap_prng_init ( unsigned int  seed)

Seeds the default random number generation function with the given seed.

The default random number generation function will use getrandom() if available, ignoring the seed.

Parameters
seedThe seed for the pseudo random number generator.

Definition at line 76 of file coap_prng.c.

+ Here is the caller graph for this function:

◆ coap_set_prng()

void coap_set_prng ( coap_rand_func_t  rng)

Replaces the current random number generation function with the default function rng.

Parameters
rngThe random number generation function to use.

Definition at line 71 of file coap_prng.c.