ATmega644 Smart-Card
Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
RNG Class Reference

Class that provides a random number generator. The RNG can be seeded by reading noise from an unused ADC. More...

#include <rng.h>

Collaboration diagram for RNG:
Collaboration graph

Public Member Functions

 RNG ()=default
 Construct a new RNG object.
 
void seed ()
 Seed the RNG by reading the ADC's LSB 8 times. More...
 
uint8_t rand ()
 Create a pseudo-random number between 0 and 255. More...
 

Static Public Member Functions

static void init ()
 Initialize the RNG & underlying ADC.
 

Static Private Member Functions

static bit_t readADC ()
 Read the LSB from ADC0. More...
 

Private Attributes

uint8_t mRand = 0
 The RNG's state.
 

Detailed Description

Class that provides a random number generator. The RNG can be seeded by reading noise from an unused ADC.

Authors
Philipp Karg (phili.nosp@m.pp.k.nosp@m.arg@t.nosp@m.um.d.nosp@m.e)
Date
23.06.2022

Member Function Documentation

◆ rand()

uint8_t RNG::rand ( )

Create a pseudo-random number between 0 and 255.

Simple 8-bit adaption of the Xorshift PRNG.

Returns
(uint8_t): The pseudo-random number.

◆ readADC()

static bit_t RNG::readADC ( )
staticprivate

Read the LSB from ADC0.

Precondition
Requires init() to be called before.
Returns
(bit_t): The read LSB.

◆ seed()

void RNG::seed ( )

Seed the RNG by reading the ADC's LSB 8 times.

Precondition
Requires init() to be called before.

The documentation for this class was generated from the following file: