result 1 result 2
Go back to reference home
functions
collectBytesCollect random bits from various sources.
getAvailableBytesGet number of available random bytes.
getRandomBytesCreate random bytes.

random

Random byte generation

This module provides random numbers suitable for cryptographic purposes.

A typical application looks like this:

#include <napc.h>

napc_u8 random_bytes[16];

void napc_app_setup(const char *platform) {}

bool napc_app_loop(napc_time uptime) {
	// request of 16 random bytes
	if (napc_random_getRandomBytes(16, random_bytes)) {
		// do something with random_bytes

		napc_printf("Here are your random numbers: ");

		for (int i = 0; i < 16; ++i) {
			napc_printf("%2.2x", random_bytes[i]);
		}

		napc_printf("\n");

		return false;
	}

	// collect new random data
	napc_random_collectBytes();

	return true;
}

This program will output something similar to:

Here are your random numbers: 162109b28bba5eabb17b69d83aeffd84
Version: 1.4.1
Documentation generated at 24.03.2022 03:43:18 (UTC)
Go back to reference home
functions
collectBytesCollect random bits from various sources.
getAvailableBytesGet number of available random bytes.
getRandomBytesCreate random bytes.