2016-08-02 07:51:44 +02:00
|
|
|
#include <stdlib.h>
|
2017-04-22 21:59:39 +02:00
|
|
|
#include <stdint.h>
|
2016-08-02 07:51:44 +02:00
|
|
|
|
2017-04-22 21:59:39 +02:00
|
|
|
static uint32_t seed = 1;
|
2016-08-02 07:51:44 +02:00
|
|
|
|
|
|
|
void srand(unsigned int new_seed)
|
|
|
|
{
|
|
|
|
seed = new_seed;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rand(void)
|
|
|
|
{
|
2017-04-22 21:59:39 +02:00
|
|
|
seed = 16807 * seed;
|
|
|
|
uint32_t top = ((uint32_t)1 << 31) - 1;
|
|
|
|
while(seed >= top) seed -= top;
|
2017-04-19 19:57:31 +02:00
|
|
|
/* TODO Or maybe seed = (16807 * seed) % ((1 << 31) - 1); */
|
2017-04-22 21:59:39 +02:00
|
|
|
// seed = seed * 1103515245 + 12345;
|
2016-08-02 07:51:44 +02:00
|
|
|
return seed & 0x7fffffff;
|
|
|
|
}
|