コード例 #1
0
ファイル: game.c プロジェクト: ptigwe/imitation
void game_set_initial_configuration_population(game_t *game)
{
    game_set_initial_configuration_position(game);
    random_set_seed(time(NULL));
    
    int n = game->graph->n;
    int i;
    for(i = 0; i < n; ++i)
    {
        game->initial_config[i] = random_boolean_with_probability(game->p_c);
        game->current_config[i] = game->initial_config[i];
    }
}
コード例 #2
0
ファイル: random_test.c プロジェクト: stnuessl/libvci
void test_seeding(unsigned int num)
{
    struct random *p1, *p2;
    unsigned int seed[] = { 1, 2, 3, 4 };
    int err;
    
    p1 = random_new();
    p2 = random_new();
    
    assert(p1);
    assert(p2);
    
    err = random_set_seed(p1, seed, ARRAY_SIZE(seed));
    assert(err == 0);
    
    err = random_set_seed(p2, seed, ARRAY_SIZE(seed));
    assert(err == 0);
    
    while(num--)
        assert(random_uint(p1) == random_uint(p2));
    
    random_delete(p1);
    random_delete(p2);
}
コード例 #3
0
ファイル: game.c プロジェクト: ptigwe/imitation
void game_set_initial_configuration_position(game_t *game)
{
    random_set_seed(time(NULL));
    
    int n = game->graph->n;
    GArray *players = g_array_new(FALSE, FALSE, sizeof(int));
    
    int i;
    for(i = 0; i < n; ++i)
    {
        game->initial_config[i] = 0;
        game->current_config[i] = 0;
        
        g_array_append_val(players, i);
    }
    
    mpq_t e;
    mpq_init(e);
    mpq_set_si(e, game->graph->n, 1);
    mpq_mul(e, game->p_c, e);
    int m = ROUND(mpq_get_d(e));
    mpq_clear(e);
    for(i = 0; i < m; ++i)
    {
        int j = random_integer(n);
        int x = g_array_index(players, int, j);
        
        game->initial_config[x] = 1;
        game->current_config[x] = 1;
        
        g_array_remove_index_fast(players, j);
        n--;
    }
    
    g_array_free(players, TRUE);
}
コード例 #4
0
ファイル: random.cpp プロジェクト: kvanberendonck/acolyte
 real_t randomize() {
   random_set_seed(intern::rand_rd());
   return 0;
 }
コード例 #5
0
static int is_slime(long map_seed, long chunkx, long chunkz) {
    /* lots of magic numbers, but they're all correct! I swear! */
    long seed;
    random_set_seed(&seed, map_seed + (chunkx * chunkx * 0x4c1906L) + (chunkx * 0x5ac0dbL) + (chunkz * chunkz * 0x4307a7L) + (chunkz * 0x5f24fL) ^ 0x3ad8025fL);
    return (random_next_int(&seed, 10) == 0);
}
コード例 #6
0
ファイル: util.cpp プロジェクト: piluke/BasicEventEngine
#include "util/collision.hpp" // Include the collision checking functions
#include "util/sound.hpp" // Include the sound effect functions
#include "util/messagebox.hpp" // Include the message box functions
#include "util/files.hpp" // Include the file handling functions
#include "util/network.hpp" // Include the networking functions

#ifndef NDEBUG // Allow the NDEBUG to disable debug support at compile time

#define DOCTEST_CONFIG_IMPLEMENT
#include "doctest.h" // Include the required unit testing library which is a git submodule in lib/doctest

// Real number function assertions
TEST_CASE("real/random") {
	REQUIRE(random(20) < (unsigned int)20);
	REQUIRE(is_between((int)random_range(20, 40), 20, 40));
	REQUIRE(random_set_seed(5) == (unsigned int)5);
	REQUIRE(random_reset_seed() != (unsigned int)DEFAULT_RANDOM_SEED);
	REQUIRE(randomize() != (unsigned int)DEFAULT_RANDOM_SEED);
}
TEST_CASE("real/math") {
	REQUIRE(sign(5) == 1);
	REQUIRE(sign(0) == 0);
	REQUIRE(sign(-5) == -1);
	REQUIRE(sign(5.0) == 1);
	REQUIRE(sign(0.0) == 0);
	REQUIRE(sign(-5.0) == -1);
	REQUIRE(sqr(5) == 25);
	REQUIRE(sqr(5.0) == 25.0);
	REQUIRE(logn(5.0, 1.0) == 0.0);
	REQUIRE(logn(5.0, 5.0) == 1.0);
	REQUIRE(logn(5.0, 10.0) == doctest::Approx(1.431).epsilon(0.001));