Difference between revisions of "Gb.pickRandomSeed"
From Gamebuino Wiki
(Created page with "{{lowercase}} __NOTOC__ == Description == Picks a random seed using a mix of the battery voltage, ambient light sensor and the time elapsed since start up. It should be placed...") |
(Explanation of the function) |
||
Line 3: | Line 3: | ||
== Description == | == Description == | ||
Picks a random seed using a mix of the battery voltage, ambient light sensor and the time elapsed since start up. It should be placed right after <code>gb.begin()</code> and <code>gb.titleScreen()</code>, this way the random seed will depend on how long the user takes to press "A" to leave the title screen. | Picks a random seed using a mix of the battery voltage, ambient light sensor and the time elapsed since start up. It should be placed right after <code>gb.begin()</code> and <code>gb.titleScreen()</code>, this way the random seed will depend on how long the user takes to press "A" to leave the title screen. | ||
+ | |||
+ | The function is defined in the library as follows: | ||
+ | |||
+ | <code> | ||
+ | void Gamebuino::pickRandomSeed(){ | ||
+ | :randomSeed(battery.voltage * ~micros() + backlight.ambientLight + micros()); | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | The range of values of each part of the function are: | ||
+ | * <code>battery.voltage</code> : 4200 to 3500 | ||
+ | * <code>~micros()</code> : -1 to -4,294,967,293 | ||
+ | * <code>backlight.ambientLight</code> : 0 to 1024 | ||
+ | * <code>micros()</code> : 0 to 4,294,967,292 | ||
+ | |||
+ | This allows seed values ranging from 0 to 4294964116 (for an unsigned long). | ||
+ | Realistically, values are expected to be in the range of 615,970 to 4,293,588,651. (Achieved using a fully charged Gamebuino) | ||
== Syntax == | == Syntax == |
Revision as of 2014-08-04T22:26:21
Description
Picks a random seed using a mix of the battery voltage, ambient light sensor and the time elapsed since start up. It should be placed right after gb.begin()
and gb.titleScreen()
, this way the random seed will depend on how long the user takes to press "A" to leave the title screen.
The function is defined in the library as follows:
void Gamebuino::pickRandomSeed(){
- randomSeed(battery.voltage * ~micros() + backlight.ambientLight + micros());
}
The range of values of each part of the function are:
-
battery.voltage
: 4200 to 3500 -
~micros()
: -1 to -4,294,967,293 -
backlight.ambientLight
: 0 to 1024 -
micros()
: 0 to 4,294,967,292
This allows seed values ranging from 0 to 4294964116 (for an unsigned long). Realistically, values are expected to be in the range of 615,970 to 4,293,588,651. (Achieved using a fully charged Gamebuino)
Syntax
gb.pickRandomSeed();
Parameters
none
Returns
none