Fast random number generator functions. More...
Functions | |
unsigned long | xorshift96 () |
Random number generator. More... | |
void | randSeed (long seed) |
Initialises Mozzi's (pseudo)random number generator xorshift96(), which is used in Mozzi's rand() function. More... | |
void | randSeed () |
Initialises Mozzi's (pseudo)random number generator xorshift96(), which is used in Mozzi's rand() function. More... | |
void | xorshiftSeed (long seed) |
Initialises Mozzi's (pseudo)random number generator xorshift96() with a chosen seed number. More... | |
int8_t | rand (int8_t minval, int8_t maxval) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi. More... | |
uint8_t | rand (uint8_t minval, uint8_t maxval) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi. More... | |
int | rand (int minval, int maxval) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi. More... | |
unsigned int | rand (unsigned int minval, unsigned int maxval) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi. More... | |
int8_t | rand (int8_t maxval) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi. More... | |
uint8_t | rand (uint8_t maxval) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi. More... | |
int | rand (int maxval) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi. More... | |
unsigned int | rand (unsigned int maxval) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi. More... | |
uint8_t | randMidiNote () |
Generates a random number in the range for midi notes. More... | |
unsigned int | randPrime (unsigned int n) |
Generates a random prime number between 0 and the n-1th prime number. More... | |
unsigned int | randPrimeUpTo (unsigned int n) |
Generates a random prime number between 0 and the given input number inclusive. More... | |
Fast random number generator functions.
These replace Arduino random() which is so slow it will stop your audio. They can even be used to generate audio noise.
int8_t rand | ( | int8_t | minval, |
int8_t | maxval | ||
) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi.
minval | the minimum signed uint8_t value of the range to be chosen from. Minval will be the minimum value possibly returned by the function. |
maxval | the maximum signed uint8_t value of the range to be chosen from. Maxval-1 will be the largest value possibly returned by the function. |
Definition at line 171 of file mozzi_rand.cpp.
uint8_t rand | ( | uint8_t | minval, |
uint8_t | maxval | ||
) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi.
minval | the minimum unsigned uint8_t value of the range to be chosen from. Minval will be the minimum value possibly returned by the function. |
maxval | the maximum unsigned uint8_t value of the range to be chosen from. Maxval-1 will be the largest value possibly returned by the function. |
Definition at line 183 of file mozzi_rand.cpp.
int rand | ( | int | minval, |
int | maxval | ||
) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi.
minval | the minimum signed int value of the range to be chosen from. Minval will be the minimum value possibly returned by the function. |
maxval | the maximum signed int value of the range to be chosen from. Maxval-1 will be the largest value possibly returned by the function. |
Definition at line 195 of file mozzi_rand.cpp.
unsigned int rand | ( | unsigned int | minval, |
unsigned int | maxval | ||
) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi.
minval | the minimum unsigned int value of the range to be chosen from. Minval will be the minimum value possibly returned by the function. |
maxval | the maximum unsigned int value of the range to be chosen from. Maxval-1 will be the largest value possibly returned by the function. |
Definition at line 207 of file mozzi_rand.cpp.
int8_t rand | ( | int8_t | maxval | ) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi.
maxval | the maximum signed uint8_t value of the range to be chosen from. Maxval-1 will be the largest value possibly returned by the function. |
Definition at line 218 of file mozzi_rand.cpp.
uint8_t rand | ( | uint8_t | maxval | ) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi.
maxval | the maximum unsigned uint8_t value of the range to be chosen from. Maxval-1 will be the largest value possibly returned by the function. |
Definition at line 229 of file mozzi_rand.cpp.
int rand | ( | int | maxval | ) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi.
maxval | the maximum signed int value of the range to be chosen from. Maxval-1 will be the largest value possibly returned by the function. |
Definition at line 240 of file mozzi_rand.cpp.
unsigned int rand | ( | unsigned int | maxval | ) |
Ranged random number generator, faster than Arduino's built-in random function, which is too slow for generating at audio rate with Mozzi.
maxval | the maximum unsigned int value of the range to be chosen from. Maxval-1 will be the largest value possibly returned by the function. |
Definition at line 251 of file mozzi_rand.cpp.
uint8_t randMidiNote | ( | ) |
Generates a random number in the range for midi notes.
Definition at line 261 of file mozzi_rand.cpp.
|
inline |
Generates a random prime number between 0 and the n-1th prime number.
This uses a stored array of primes, which takes about 2.5k of progmem.
n | the maximum index in the series of primes up to which numbers will be returned. The maximum is 1128. |
|
inline |
Generates a random prime number between 0 and the given input number inclusive.
This uses a stored array of primes up to 10000, which takes about 2.5k of progmem.
n | the upper limit of the random prime number to be generated. The maximum is 10000. |
void randSeed | ( | long | seed | ) |
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.
seed | a number to use as a seed. |
Definition at line 53 of file mozzi_rand.cpp.
void randSeed | ( | ) |
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.
Definition at line 117 of file mozzi_rand.cpp.
unsigned long xorshift96 | ( | ) |
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
Definition at line 26 of file mozzi_rand.cpp.
void xorshiftSeed | ( | long | seed | ) |
Initialises Mozzi's (pseudo)random number generator xorshift96() with a chosen seed number.
seed | a number to use as a seed. |
Definition at line 158 of file mozzi_rand.cpp.