2014-05-18 10:10:04 -04:00
|
|
|
/*
|
|
|
|
* Copyright 2014 (c) Anna Schumaker
|
|
|
|
*/
|
2014-06-21 09:37:47 -04:00
|
|
|
#ifndef OCARINA_CORE_RANDOM_H
|
|
|
|
#define OCARINA_CORE_RANDOM_H
|
2014-05-18 10:10:04 -04:00
|
|
|
|
|
|
|
#ifndef CONFIG_TEST
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
static inline void _seed_random(unsigned int n) { srand(time(NULL) + n); }
|
|
|
|
static inline unsigned int _pick_random() { return rand(); }
|
|
|
|
|
|
|
|
#else /* CONFIG_TEST */
|
|
|
|
|
|
|
|
void _seed_random(unsigned int);
|
|
|
|
unsigned int _pick_random();
|
|
|
|
|
|
|
|
#endif /* CONFIG_TEST */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline void random_seed(unsigned int n)
|
|
|
|
{
|
|
|
|
_seed_random(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int random(unsigned int min, unsigned int max)
|
|
|
|
{
|
|
|
|
if (min >= max)
|
|
|
|
return min;
|
|
|
|
return min + (_pick_random() % (max - min));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-21 09:37:47 -04:00
|
|
|
#endif /* OCARINA_CORE_RANDOM_H */
|