mirror of https://github.com/MLXXXp/Arduboy2.git
Fix initRandomSeed(). Minor code and doc changes
The call to generateRandomSeed() in initRandomSeed() was missing parentheses. Added keyword for generateRandomSeed. Minor code changes, and documentation changes and additions.
This commit is contained in:
parent
4c2e412985
commit
0eae58c760
|
@ -64,6 +64,7 @@ flashlight KEYWORD2
|
|||
flipVertical KEYWORD2
|
||||
flipHorizontal KEYWORD2
|
||||
freeRGBled KEYWORD2
|
||||
generateRandomSeed KEYWORD2
|
||||
getBuffer KEYWORD2
|
||||
getCursorX KEYWORD2
|
||||
getCursorY KEYWORD2
|
||||
|
|
|
@ -277,13 +277,15 @@ int Arduboy2Base::cpuLoad()
|
|||
|
||||
unsigned long Arduboy2Base::generateRandomSeed()
|
||||
{
|
||||
unsigned long seed;
|
||||
|
||||
power_adc_enable(); // ADC on
|
||||
|
||||
// do an ADC read from an unconnected input pin
|
||||
ADCSRA |= _BV(ADSC); // start conversion (ADMUX has been pre-set in boot())
|
||||
while (bit_is_set(ADCSRA, ADSC)) { } // wait for conversion complete
|
||||
|
||||
unsigned long seed = (static_cast<unsigned long>(ADC) << 16) + micros();
|
||||
seed = ((unsigned long)ADC << 16) + micros();
|
||||
|
||||
power_adc_disable(); // ADC off
|
||||
|
||||
|
@ -292,7 +294,7 @@ unsigned long Arduboy2Base::generateRandomSeed()
|
|||
|
||||
void Arduboy2Base::initRandomSeed()
|
||||
{
|
||||
randomSeed(generateRandomSeed);
|
||||
randomSeed(generateRandomSeed());
|
||||
}
|
||||
|
||||
/* Graphics */
|
||||
|
|
|
@ -695,13 +695,17 @@ class Arduboy2Base : public Arduboy2Core
|
|||
/** \brief
|
||||
* Create a seed suitable for use with a random number generator.
|
||||
*
|
||||
* \return A random value that can be used to seed a random number generator.
|
||||
*
|
||||
* \details
|
||||
* The seed is generated with a random value derived from entropy from an
|
||||
* The returned value will be a random value derived from entropy from an
|
||||
* ADC reading of a floating pin combined with the microseconds since boot.
|
||||
*
|
||||
* This method is still most effective when called after a semi-random time,
|
||||
* such as after a user hits a button to start a game or other semi-random
|
||||
* event.
|
||||
*
|
||||
* \see initRandomSeed()
|
||||
*/
|
||||
unsigned long generateRandomSeed();
|
||||
|
||||
|
@ -711,11 +715,14 @@ class Arduboy2Base : public Arduboy2Core
|
|||
* \details
|
||||
* The Arduino random number generator is seeded with a random value
|
||||
* derived from entropy from an ADC reading of a floating pin combined with
|
||||
* the microseconds since boot.
|
||||
* the microseconds since boot. The seed value is provided by calling the
|
||||
* `generateRandomSeed()` function.
|
||||
*
|
||||
* This method is still most effective when called after a semi-random time,
|
||||
* such as after a user hits a button to start a game or other semi-random
|
||||
* event.
|
||||
*
|
||||
* \see generateRandomSeed()
|
||||
*/
|
||||
void initRandomSeed();
|
||||
|
||||
|
|
Loading…
Reference in New Issue