core: Remove random functions

I no longer need these now that the queue is using the glib
g_random_int_range() function.

Implements #32: Remove custom RNG code
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-03-11 16:26:28 -05:00
parent f1bcc7746e
commit d825e2d481
7 changed files with 0 additions and 106 deletions

View File

@ -2,7 +2,6 @@
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/queue.h>
#include <core/random.h>
#include <core/string.h>
#include <stdlib.h>

View File

@ -1,21 +0,0 @@
/*
* Copyright 2014 (c) Anna Schumaker
*/
#ifdef CONFIG_TESTING
#include <core/random.h>
static unsigned int _random_value = 0;
void _seed_random(unsigned int n)
{
_random_value = n;
}
unsigned int _pick_random()
{
return ++_random_value;
}
#endif /* CONFIG_TESTING */

View File

@ -1,36 +0,0 @@
/*
* Copyright 2014 (c) Anna Schumaker
*/
#ifndef OCARINA_CORE_RANDOM_H
#define OCARINA_CORE_RANDOM_H
#ifdef CONFIG_TESTING
void _seed_random(unsigned int);
unsigned int _pick_random();
#else /* CONFIG_TESTING */
#include <stdlib.h>
static inline void _seed_random(unsigned int n) { srand(time(NULL) + n); }
static inline unsigned int _pick_random() { return rand(); }
#endif /* CONFIG_TESTING */
/* Seed the random number generator. */
static inline void random_seed(unsigned int n)
{
_seed_random(n);
}
/* Returns a random number X, where min <= value <= max. */
static inline unsigned int random_range(unsigned int min, unsigned int max)
{
if (min >= max)
return min;
return min + (_pick_random() % (max - min));
}
#endif /* OCARINA_CORE_RANDOM_H */

View File

@ -1,6 +1,5 @@
version
string
random
file
date
idle

View File

@ -26,7 +26,6 @@ Export("core_objs", "CoreTest")
res += [ CoreTest("version") ]
res += [ CoreTest("string") ]
res += [ CoreTest("random") ]
res += [ CoreTest("file") ]
res += [ CoreTest("date") ]
res += [ CoreTest("idle") ]

View File

@ -3,7 +3,6 @@
*/
#include <core/filter.h>
#include <core/queue.h>
#include <core/random.h>
#include <core/tags/tags.h>
#include <tests/test.h>

View File

@ -1,45 +0,0 @@
/*
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/random.h>
#include <core/string.h>
#include <tests/test.h>
static void test_rng(unsigned int seed)
{
random_seed(seed);
for (unsigned int i = 0; i <= 10; i++) {
if (i <= seed)
test_equal(random_range(seed, i), seed);
else
test_equal(random_range(seed, i), seed + (i % (i - seed)));
}
}
static void test_rng_0() { test_rng(0); }
static void test_rng_1() { test_rng(1); }
static void test_rng_2() { test_rng(2); }
static void test_rng_3() { test_rng(3); }
static void test_rng_4() { test_rng(4); }
static void test_rng_5() { test_rng(5); }
static void test_rng_6() { test_rng(6); }
static void test_rng_7() { test_rng(7); }
static void test_rng_8() { test_rng(8); }
static void test_rng_9() { test_rng(9); }
DECLARE_UNIT_TESTS(
UNIT_TEST("Random Number Generator (seed = 0)", test_rng_0),
UNIT_TEST("Random Number Generator (seed = 1)", test_rng_1),
UNIT_TEST("Random Number Generator (seed = 2)", test_rng_2),
UNIT_TEST("Random Number Generator (seed = 3)", test_rng_3),
UNIT_TEST("Random Number Generator (seed = 4)", test_rng_4),
UNIT_TEST("Random Number Generator (seed = 5)", test_rng_5),
UNIT_TEST("Random Number Generator (seed = 6)", test_rng_6),
UNIT_TEST("Random Number Generator (seed = 7)", test_rng_7),
UNIT_TEST("Random Number Generator (seed = 8)", test_rng_8),
UNIT_TEST("Random Number Generator (seed = 9)", test_rng_9),
);