libcoap 4.3.5-develop-72190a8
Loading...
Searching...
No Matches
Pseudo Random Numbers

API for generating pseudo random numbers. More...

+ Collaboration diagram for Pseudo Random Numbers:

Typedefs

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

Functions

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

Detailed Description

API for generating 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 32 of file coap_prng.h.

Function Documentation

◆ coap_prng()

COAP_API 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 66 of file coap_prng.c.

+ Here is the call graph for this function:

◆ coap_prng_init()

COAP_API 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 59 of file coap_prng.c.

+ Here is the call 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 161 of file coap_prng.c.