Mozzi  version v2.0
sound synthesis library for Arduino
MozziPrivate::MozziRandPrivate Class Reference

Detailed Description

Definition at line 17 of file mozzi_rand_p.h.

Static Public Member Functions

static uint32_t xorshift96 ()
 
static void autoSeed ()
 

Friends

void randSeed ()
 Initialises Mozzi's (pseudo)random number generator xorshift96(), which is used in Mozzi's rand() function. More...
 
void randSeed (uint32_t)
 Initialises Mozzi's (pseudo)random number generator xorshift96(), which is used in Mozzi's rand() function. More...
 
uint32_t xorshift96 ()
 Random number generator. More...
 

Friends And Related Function Documentation

◆ randSeed [1/2]

void randSeed ( )
friend

Initialises Mozzi's (pseudo)random number generator xorshift96(), which is used in Mozzi's rand() function.

This can be useful if you want random sequences to be different on each run of a sketch, by seeding with a fairly random input. randSeed() called without a parameter uses noise from reading the Arduino's internal temperature as the seed, a technique discussed at http://arduino.cc/forum/index.php/topic,38091.0.html, borrowing code put there by Rob Tillaart.

Note
Intialization of the random seed is done differently on different MCUs, but is nowhere near perfect for most (and for some it is not even implemented at all). Many implementations (e.g. on AVR, STM32) simply rely on reading a (hopefully noisy) internal temperature sensor. You will often get better results by calling analogRead() - not mozziAnalogRead(0), in this case! - on one or two floating (non-connected) analog pins.

Definition at line 59 of file mozzi_rand.h.

◆ randSeed [2/2]

void randSeed ( uint32_t  seed)
friend

Initialises Mozzi's (pseudo)random number generator xorshift96(), which is used in Mozzi's rand() function.

This can be useful if you want random sequences to be different on each run of a sketch, by seeding with fairly random input, such as analogRead() on an unconnected pin (as explained in the Arduino documentation for randomSeed(). randSeed is the same as xorshift96Seed(), but easier to remember.

Parameters
seeda number to use as a seed.

Definition at line 43 of file mozzi_rand_p.h.

◆ xorshift96

uint32_t xorshift96 ( )
friend

Random number generator.

A faster replacement for Arduino's random function, which is too slow to use with Mozzi. Based on Marsaglia, George. (2003). Xorshift RNGs. http://www.jstatsoft.org/v08/i14/xorshift.pdf

Returns
a random 32 bit integer.

Definition at line 30 of file mozzi_rand.h.