deadbeef_rand.c

Go to the documentation of this file.
00001 #include "deadbeef_rand.h"
00002 
00003 static uint32_t deadbeef_seed;
00004 static uint32_t deadbeef_beef = 0xdeadbeef;
00005 
00006 /** Generate a 32-bit random number.
00007  *
00008  * Before using this function, you should seed the generator by
00009  * calling deadbeef_srand().
00010  */
00011 uint32_t deadbeef_rand() {
00012   deadbeef_seed = (deadbeef_seed << 7) ^ ((deadbeef_seed >> 25) + deadbeef_beef);
00013   deadbeef_beef = (deadbeef_beef << 7) ^ ((deadbeef_beef >> 25) + 0xdeadbeef);
00014   return deadbeef_seed;
00015 }
00016 
00017 /** Seed the deadbeef random number generator.
00018  *
00019  * Starting from the same seed, multiple runs of the deadbeef random
00020  * number generator will generate identical sequences of pseudo-random
00021  * numbers. This is sometime useful. In cases where it is desirable to
00022  * have different runs of the generator generate different sequences,
00023  * you should seed them with different seeds.
00024  *
00025  * @param seed The value to seed the deadbeef generator with
00026  */
00027 void deadbeef_srand(uint32_t seed) {
00028   deadbeef_seed = seed;
00029   deadbeef_beef = 0xdeadbeef;
00030 }

Generated on Thu Dec 6 14:01:04 2007 for deadbeef_rand by  doxygen 1.5.1