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:
parent
cea50ae37f
commit
068afd6276
|
@ -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>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Copyright 2014 (c) Anna Schumaker
|
||||
*/
|
||||
#ifdef CONFIG_TESTING
|
|
@ -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 */
|
||||
|
|
|
@ -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") ]
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue