void Randomize();
Initializes the random number generator to return a variable random number sequence. Consider using RandomSetSeed() for a fixed and repeatable random number sequence.
Availability
Available in DragonFireSDK 1.0 and later.
Example
Description: This example will generate a new series of random numbers each time the user touches the screen.
#include "DragonFireSDK.h" #include <string.h>
// Set MAX_RND to the total number of random values that will be printed // to the debug window. #define MAX_RND 40 // Set SEQUENCE_LENGTH to the maximum number of random numbers times two // to allow for commas between values, plus add room for the length of // the sequence prefix. #define SEQUENCE_LENGTH (MAX_RND * 2) + 11
int OnTouchArea(int id, int event, int x, int y);
void AppMain() { TouchAdd(0, 0, 320, 480, OnTouchArea, 0); }
int OnTouchArea(int id, int event, int x, int y) { // Event 3 is called when the user lifts their finger from the touch area. if (event == 3) { // Call the randome number generator. Randomize(); // Declare the Sequence buffer. char Sequence[SEQUENCE_LENGTH]; // Initialize the buffer with null characters. memset(Sequence, 0, SEQUENCE_LENGTH); // Add our prefix to the output string. StrAppend(Sequence, "Sequence: "); // Declare a buffer for the next random number. char Num[2]; // Loop to build the random number string: for (int i = 0; i < MAX_RND; ++i) { // Format the integer as a decimal string. sprintf(Num, "%d", Random(10)); // Add the Num buffer to our output buffer. StrAppend(Sequence, Num); // Add a comma to the sequence to separate the values, // except for the final value. if (i < MAX_RND - 1) { StrAppend(Sequence, ","); } } // Add a return at the end of the line StrAppend(Sequence, "\n"); // Output the sequence of random numbers to the debug window. printf(Sequence); } return(0); }
void AppExit() {
}
void OnTimer() {
} |