core/random: Convert to C

And convert the unit test while we're at it.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-09-09 09:00:17 -04:00
parent cea50ae37f
commit 068afd6276
6 changed files with 11 additions and 17 deletions

View File

@ -2,7 +2,9 @@
* Copyright 2013 (c) Anna Schumaker.
*/
#include <core/queue.h>
extern "C" {
#include <core/random.h>
}
#include <core/string.h>
#include <algorithm>

View File

@ -1,4 +1,4 @@
/**
/*
* Copyright 2014 (c) Anna Schumaker
*/
#ifdef CONFIG_TESTING

View File

@ -1,4 +1,4 @@
/**
/*
* Copyright 2014 (c) Anna Schumaker
*/
#ifndef OCARINA_CORE_RANDOM_H
@ -18,23 +18,14 @@ static inline unsigned int _pick_random() { return rand(); }
#endif /* CONFIG_TESTING */
/**
* Seed the random number generator.
*
* @param n Value used to initialize the RNG
*/
/* Seed the random number generator. */
static inline void random_seed(unsigned int n)
{
_seed_random(n);
}
/**
* Get a random number in the specified range.
*
* @param min Minimum value that will be returned.
* @param max Maximum value that will be returned.
* @return A random value where min <= value <= max.
*/
/* Returns a random number X, where min <= value <= max. */
static inline unsigned int random_range(unsigned int min, unsigned int max)
{
if (min >= max)
@ -42,5 +33,4 @@ static inline unsigned int random_range(unsigned int min, unsigned int max)
return min + (_pick_random() % (max - min));
}
#endif /* OCARINA_CORE_RANDOM_H */

View File

@ -15,7 +15,7 @@ Export("core_objs")
res = [ CoreTest("version", "version.c") ]
res += [ CoreTest("string", "string.c") ]
res += [ CoreTest("random", "random.cpp") ]
res += [ CoreTest("random", "random.c") ]
res += [ CoreTest("file", "file.cpp") ]
res += [ CoreTest("database", "database.cpp") ]
res += [ CoreTest("index", "index.cpp") ]

View File

@ -2,7 +2,9 @@
* Copyright 2014 (c) Anna Schumaker.
*/
#include <core/queue.h>
extern "C" {
#include <core/random.h>
}
#include <core/tags/tags.h>
#include "test.h"

View File

@ -3,7 +3,7 @@
*/
#include <core/random.h>
#include <core/string.h>
#include "test.h"
#include <tests/test.h>
static void test_rng(unsigned int seed)