From dff34f8e92850a17cbda10d4382e2e86285a39ca Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Tue, 13 Jan 2015 02:39:38 +0100 Subject: [PATCH 1/7] increase speed of peasant growth calculation --- src/laws.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/laws.c b/src/laws.c index 761ddab00..eb55d7359 100755 --- a/src/laws.c +++ b/src/laws.c @@ -285,7 +285,7 @@ static void peasants(region * r) glueck = a->data.i * 1000; } - for (n = peasants; n; --n) { + for (n = peasants; n && glueck; --n) { int chances = 0; if (glueck > 0) { From 51d52aaf7fd333ff8985c8310013e10dec6830f4 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Wed, 14 Jan 2015 22:33:58 +0100 Subject: [PATCH 2/7] implementing a much faster version of peasant growth calculation --- src/laws.c | 63 +++++++++++++++++++++++++---------------- src/laws.h | 3 ++ src/laws.test.c | 31 ++++++++++++++++++++ src/test_eressea.c | 1 + src/util/CMakeLists.txt | 1 + src/util/rng.h | 1 + src/util/rng.test.c | 26 +++++++++++++++++ 7 files changed, 101 insertions(+), 25 deletions(-) create mode 100644 src/util/rng.test.c diff --git a/src/laws.c b/src/laws.c index eb55d7359..92f10f52a 100755 --- a/src/laws.c +++ b/src/laws.c @@ -259,6 +259,40 @@ static void calculate_emigration(region * r) } /** Bauern vermehren sich */ +int fast_peasant_luck_effect(int peasants, int luck, int maxp) { + int births=0; + double mean = _min(luck, peasants) * PEASANTLUCK * PEASANTGROWTH / (float) 10000 * ((peasants/(float)maxp < .9)?1:PEASANTFORCE); + + births = RAND_ROUND(normalvariate(mean, mean/2+1)); + if (births <= 0) + births = 1; + if (births>peasants/2) + births=peasants/2+1; + return (int)births; +} + +int peasant_luck_effect(int peasants, int luck, int maxp) { + int n, births=0; + for (n = peasants; n && luck; --n) { + int chances = 0; + + if (luck > 0) { + --luck; + chances += PEASANTLUCK; + } + + while (chances--) { + if (rng_int() % 10000 < PEASANTGROWTH) { + /* Only raise with 75% chance if peasants have + * reached 90% of maxpopulation */ + if (peasants / (float)maxp < 0.9 || chance(PEASANTFORCE)) { + ++births; + } + } + } + } + return births; +} static void peasants(region * r) { @@ -272,37 +306,16 @@ static void peasants(region * r) * wollen nicht! */ if (peasants > 0 && get_param_int(global.parameters, "rules.peasants.growth", 1)) { - int glueck = 0; + int luck = 0; double fraction = peasants * 0.0001F * PEASANTGROWTH; - int births = (int)fraction; + int births = RAND_ROUND(fraction); attrib *a = a_find(r->attribs, &at_peasantluck); - if (rng_double() < (fraction - births)) { - /* because we don't want regions that never grow pga. rounding. */ - ++births; - } if (a != NULL) { - glueck = a->data.i * 1000; + luck = a->data.i * 1000; } - for (n = peasants; n && glueck; --n) { - int chances = 0; - - if (glueck > 0) { - --glueck; - chances += PEASANTLUCK; - } - - while (chances--) { - if (rng_int() % 10000 < PEASANTGROWTH) { - /* Only raise with 75% chance if peasants have - * reached 90% of maxpopulation */ - if (peasants / (float)maxp < 0.9 || chance(PEASANTFORCE)) { - ++births; - } - } - } - } + births += peasant_luck_effect(peasants, luck, maxp); peasants += births; } diff --git a/src/laws.h b/src/laws.h index 27232982b..4efe28b37 100755 --- a/src/laws.h +++ b/src/laws.h @@ -107,6 +107,9 @@ extern "C" { int armedmen(const struct unit *u, bool siege_weapons); void force_leave(struct region *r); + int peasant_luck_effect(int peasants, int luck, int maxp); + int fast_peasant_luck_effect(int peasants, int luck, int maxp); + #ifdef __cplusplus } diff --git a/src/laws.test.c b/src/laws.test.c index 2b2f0bb9f..1f4251be1 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -691,6 +692,35 @@ static void test_reserve_self(CuTest *tc) { test_cleanup(); } +static void test_peasant_luck(CuTest *tc) { + int p, l, max, n=0, wrong=0, total=0; + for (p=1; p<10000; p = (int)(_max(p*1.2+1, p+50))) { + for (l=1; l<2000; l=(int)(_max(l*1.5+1, l+10))) { + for (max=p/5; max<7*p; max=(int)(max*2+1)) { + double births = 0, births2=0, bsum1, bsum2; + double birthsm = l * PEASANTLUCK * PEASANTGROWTH / (float) 10000 * ((p/(float)max < .9)?1:PEASANTFORCE); + for (n=0;n<10;++n) { + births = peasant_luck_effect(p, l, max); + births2 = fast_peasant_luck_effect(p,l,max); + bsum1 += births; + bsum2 += births2; + printf("%f\t%f\t%f\t%d\t%d\t%d\t1#\n", birthsm, births2, births, p,l,max); + } + bsum1 /= 50; + bsum2 /= 50; + if ((bsum1-bsum2>.5 || bsum2-bsum1>.5) && (bsum1/bsum2>1.1 || bsum2/bsum1>1.1)){ + ++wrong; + } + ++total; + } + } + printf("#\n"); + } + printf("%d / %d\n", wrong, total); + +} + + CuSuite *get_laws_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -721,6 +751,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_force_leave_buildings); SUITE_ADD_TEST(suite, test_force_leave_ships); SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean); + SUITE_ADD_TEST(suite, test_peasant_luck); return suite; } diff --git a/src/test_eressea.c b/src/test_eressea.c index b8ff259b6..91b55fac4 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -53,6 +53,7 @@ int RunAllTests(void) RUN_TESTS(suite, umlaut); RUN_TESTS(suite, unicode); RUN_TESTS(suite, strings); + RUN_TESTS(suite, rng); /* kernel */ RUN_TESTS(suite, alliance); RUN_TESTS(suite, unit); diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index a08046ae2..249b1c61c 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -9,6 +9,7 @@ bsdstring.test.c functions.test.c umlaut.test.c unicode.test.c +rng.test.c ) SET(_FILES diff --git a/src/util/rng.h b/src/util/rng.h index 8737190c6..ca9e8fb23 100644 --- a/src/util/rng.h +++ b/src/util/rng.h @@ -39,6 +39,7 @@ extern "C" { # define rng_double ((rand()%RAND_MAX)/(double)RAND_MAX) # define RNG_RAND_MAX RAND_MAX #endif +#define RAND_ROUND(fractional) ((rng_double() < fractional-(int)fractional)?((int)fractional+1):((int)fractional)) #ifdef __cplusplus } #endif diff --git a/src/util/rng.test.c b/src/util/rng.test.c new file mode 100644 index 000000000..d73c23ef4 --- /dev/null +++ b/src/util/rng.test.c @@ -0,0 +1,26 @@ +#include +#include + +#include "rng.h" + +static void test_rng_round(CuTest * tc) +{ + double f; + int i,r; + for (i=0; i<1000; ++i) { + f = rng_double(); + r = RAND_ROUND(f); + CuAssertTrue(tc, f >= 0); + CuAssertTrue(tc, r <= (int) f+1); + CuAssertTrue(tc, r >= (int) f); + CuAssertTrue(tc, r == (int) r); + CuAssertTrue(tc, r == RAND_ROUND(r)); + } +} + +CuSuite *get_rng_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_rng_round); + return suite; +} From 863901d482a86b1c7c4058b566da174ff84b5074 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Thu, 15 Jan 2015 02:52:26 +0100 Subject: [PATCH 3/7] putting faster version into effect and removing pseudo-test --- src/laws.c | 5 ++++- src/laws.h | 3 --- src/laws.test.c | 30 ------------------------------ 3 files changed, 4 insertions(+), 34 deletions(-) diff --git a/src/laws.c b/src/laws.c index 92f10f52a..0eefa8be4 100755 --- a/src/laws.c +++ b/src/laws.c @@ -259,7 +259,8 @@ static void calculate_emigration(region * r) } /** Bauern vermehren sich */ -int fast_peasant_luck_effect(int peasants, int luck, int maxp) { +#ifndef SLOWLUCK +int peasant_luck_effect(int peasants, int luck, int maxp) { int births=0; double mean = _min(luck, peasants) * PEASANTLUCK * PEASANTGROWTH / (float) 10000 * ((peasants/(float)maxp < .9)?1:PEASANTFORCE); @@ -271,6 +272,7 @@ int fast_peasant_luck_effect(int peasants, int luck, int maxp) { return (int)births; } +#else int peasant_luck_effect(int peasants, int luck, int maxp) { int n, births=0; for (n = peasants; n && luck; --n) { @@ -293,6 +295,7 @@ int peasant_luck_effect(int peasants, int luck, int maxp) { } return births; } +#endif static void peasants(region * r) { diff --git a/src/laws.h b/src/laws.h index 4efe28b37..27232982b 100755 --- a/src/laws.h +++ b/src/laws.h @@ -107,9 +107,6 @@ extern "C" { int armedmen(const struct unit *u, bool siege_weapons); void force_leave(struct region *r); - int peasant_luck_effect(int peasants, int luck, int maxp); - int fast_peasant_luck_effect(int peasants, int luck, int maxp); - #ifdef __cplusplus } diff --git a/src/laws.test.c b/src/laws.test.c index 1f4251be1..117e1fb3c 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -692,35 +692,6 @@ static void test_reserve_self(CuTest *tc) { test_cleanup(); } -static void test_peasant_luck(CuTest *tc) { - int p, l, max, n=0, wrong=0, total=0; - for (p=1; p<10000; p = (int)(_max(p*1.2+1, p+50))) { - for (l=1; l<2000; l=(int)(_max(l*1.5+1, l+10))) { - for (max=p/5; max<7*p; max=(int)(max*2+1)) { - double births = 0, births2=0, bsum1, bsum2; - double birthsm = l * PEASANTLUCK * PEASANTGROWTH / (float) 10000 * ((p/(float)max < .9)?1:PEASANTFORCE); - for (n=0;n<10;++n) { - births = peasant_luck_effect(p, l, max); - births2 = fast_peasant_luck_effect(p,l,max); - bsum1 += births; - bsum2 += births2; - printf("%f\t%f\t%f\t%d\t%d\t%d\t1#\n", birthsm, births2, births, p,l,max); - } - bsum1 /= 50; - bsum2 /= 50; - if ((bsum1-bsum2>.5 || bsum2-bsum1>.5) && (bsum1/bsum2>1.1 || bsum2/bsum1>1.1)){ - ++wrong; - } - ++total; - } - } - printf("#\n"); - } - printf("%d / %d\n", wrong, total); - -} - - CuSuite *get_laws_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -751,7 +722,6 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_force_leave_buildings); SUITE_ADD_TEST(suite, test_force_leave_ships); SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean); - SUITE_ADD_TEST(suite, test_peasant_luck); return suite; } From ec6560a2811c9609e00315343b73dbd4b736cdb8 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Thu, 15 Jan 2015 03:45:07 +0100 Subject: [PATCH 4/7] adding a nice region message --- res/core/messages.xml | 7 +++++++ src/laws.c | 9 ++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/res/core/messages.xml b/res/core/messages.xml index cbc5dd780..b5b6ee248 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -3658,6 +3658,13 @@ "$unit($unit): '$order($command)' - The unit already uses $resource($using,0)." "$unit($unit): '$order($command)' - The unit already uses $resource($using,0)." + + + + + "$if($eq($births,1),"Einen Bauern","$int($births) Bauern") besucht unverhofft der Storch." + "The stork paid an unexpected visit to $if($eq($births,1),"one peasant","$int($births) peasants")." + diff --git a/src/laws.c b/src/laws.c index 0eefa8be4..dbae94035 100755 --- a/src/laws.c +++ b/src/laws.c @@ -305,9 +305,6 @@ static void peasants(region * r) int n, satiated; int dead = 0; - /* Bis zu 1000 Bauern können Zwillinge bekommen oder 1000 Bauern - * wollen nicht! */ - if (peasants > 0 && get_param_int(global.parameters, "rules.peasants.growth", 1)) { int luck = 0; double fraction = peasants * 0.0001F * PEASANTGROWTH; @@ -318,8 +315,10 @@ static void peasants(region * r) luck = a->data.i * 1000; } - births += peasant_luck_effect(peasants, luck, maxp); - peasants += births; + luck = peasant_luck_effect(peasants, luck, maxp); + ADDMSG(&r->msgs, msg_message("peasantluck_success", "births", luck)); + + peasants += births + luck; } /* Alle werden satt, oder halt soviele für die es auch Geld gibt */ From 531ab0e7a232c41ac7ec0f35e730c19e093edd9f Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Thu, 15 Jan 2015 13:13:41 +0100 Subject: [PATCH 5/7] add configuration parameters for peasant growth and peasant luck effect --- src/laws.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/laws.c b/src/laws.c index dbae94035..7ea0da81c 100755 --- a/src/laws.c +++ b/src/laws.c @@ -258,11 +258,20 @@ static void calculate_emigration(region * r) } } + +static float peasant_growth_factor(void) { + return get_param_flt(global.parameters, "rules.peasants.growth.factor", + 0.0001F * PEASANTGROWTH); +} + /** Bauern vermehren sich */ #ifndef SLOWLUCK int peasant_luck_effect(int peasants, int luck, int maxp) { int births=0; - double mean = _min(luck, peasants) * PEASANTLUCK * PEASANTGROWTH / (float) 10000 * ((peasants/(float)maxp < .9)?1:PEASANTFORCE); + double mean = _min(luck, peasants) + * get_param_int(global.parameters, "rules.peasants.peasantluck.factor", PEASANTLUCK) + * peasant_growth_factor() + * ((peasants/(float)maxp < .9)?1:PEASANTFORCE); births = RAND_ROUND(normalvariate(mean, mean/2+1)); if (births <= 0) @@ -284,7 +293,7 @@ int peasant_luck_effect(int peasants, int luck, int maxp) { } while (chances--) { - if (rng_int() % 10000 < PEASANTGROWTH) { + if (rng_double() < peasant_growth_factor()) { /* Only raise with 75% chance if peasants have * reached 90% of maxpopulation */ if (peasants / (float)maxp < 0.9 || chance(PEASANTFORCE)) { @@ -307,7 +316,7 @@ static void peasants(region * r) if (peasants > 0 && get_param_int(global.parameters, "rules.peasants.growth", 1)) { int luck = 0; - double fraction = peasants * 0.0001F * PEASANTGROWTH; + double fraction = peasants * peasant_growth_factor(); int births = RAND_ROUND(fraction); attrib *a = a_find(r->attribs, &at_peasantluck); From 4c391ae6f6d9dcb7987264cc9558a2cb66455637 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Thu, 29 Jan 2015 23:50:45 +0100 Subject: [PATCH 6/7] implemented Enno's suggestions for peasant growth --- res/core/messages.xml | 2 +- src/laws.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/res/core/messages.xml b/res/core/messages.xml index b5b6ee248..5271d4ec7 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -3663,7 +3663,7 @@ "$if($eq($births,1),"Einen Bauern","$int($births) Bauern") besucht unverhofft der Storch." - "The stork paid an unexpected visit to $if($eq($births,1),"one peasant","$int($births) peasants")." + "The stork paid an unexpected visit to $if($eq($births,1),"a peasant","$int($births) peasants")." diff --git a/src/laws.c b/src/laws.c index 7ea0da81c..56abb724f 100755 --- a/src/laws.c +++ b/src/laws.c @@ -259,9 +259,21 @@ static void calculate_emigration(region * r) } +static float peasant_luck_factor(void) { + static float factor = -1; + + if (factor < 0) + get_param_int(global.parameters, "rules.peasants.peasantluck.factor", PEASANTLUCK); + return factor; +} + static float peasant_growth_factor(void) { - return get_param_flt(global.parameters, "rules.peasants.growth.factor", + static float factor = -1; + + if (factor < 0) + factor = get_param_flt(global.parameters, "rules.peasants.growth.factor", 0.0001F * PEASANTGROWTH); + return factor; } /** Bauern vermehren sich */ @@ -269,7 +281,7 @@ static float peasant_growth_factor(void) { int peasant_luck_effect(int peasants, int luck, int maxp) { int births=0; double mean = _min(luck, peasants) - * get_param_int(global.parameters, "rules.peasants.peasantluck.factor", PEASANTLUCK) + * peasant_luck_factor() * peasant_growth_factor() * ((peasants/(float)maxp < .9)?1:PEASANTFORCE); From a97b211e707a99f82e64e2f81a91db3c62c397bc Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Fri, 30 Jan 2015 17:40:04 +0100 Subject: [PATCH 7/7] bit of testing, code improvements, formatting --- src/laws.c | 96 ++++++++++++++++++++++----------------------- src/laws.test.c | 29 +++++++++++++- src/util/rng.test.c | 22 +++++------ 3 files changed, 85 insertions(+), 62 deletions(-) diff --git a/src/laws.c b/src/laws.c index 56abb724f..2e5aafc78 100755 --- a/src/laws.c +++ b/src/laws.c @@ -259,62 +259,58 @@ static void calculate_emigration(region * r) } -static float peasant_luck_factor(void) { - static float factor = -1; - - if (factor < 0) - get_param_int(global.parameters, "rules.peasants.peasantluck.factor", PEASANTLUCK); - return factor; +static float peasant_growth_factor(void) +{ + return get_param_flt(global.parameters, "rules.peasants.growth.factor", + 0.0001F * PEASANTGROWTH); } -static float peasant_growth_factor(void) { - static float factor = -1; - - if (factor < 0) - factor = get_param_flt(global.parameters, "rules.peasants.growth.factor", - 0.0001F * PEASANTGROWTH); - return factor; -} - -/** Bauern vermehren sich */ #ifndef SLOWLUCK -int peasant_luck_effect(int peasants, int luck, int maxp) { - int births=0; - double mean = _min(luck, peasants) - * peasant_luck_factor() - * peasant_growth_factor() - * ((peasants/(float)maxp < .9)?1:PEASANTFORCE); - - births = RAND_ROUND(normalvariate(mean, mean/2+1)); - if (births <= 0) - births = 1; - if (births>peasants/2) - births=peasants/2+1; - return (int)births; +static float peasant_luck_factor(void) +{ + return get_param_int(global.parameters, "rules.peasants.peasantluck.factor", + PEASANTLUCK); +} + +static +int peasant_luck_effect(int peasants, int luck, int maxp, float variance) +{ + int births = 0; + double mean = _min(luck, peasants) * peasant_luck_factor() + * peasant_growth_factor() * ((peasants / (float)maxp < .9) ? 1 : + PEASANTFORCE); + + births = RAND_ROUND(normalvariate(mean, variance * mean)); + if (births <= 0) + births = 1; + if (births > peasants / 2) + births = peasants / 2 + 1; + return (int)births; } #else -int peasant_luck_effect(int peasants, int luck, int maxp) { - int n, births=0; - for (n = peasants; n && luck; --n) { - int chances = 0; +int peasant_luck_effect(int peasants, int luck, int maxp, float variance) { + int n, births=0; + float factor = peasant_growth_factor(); + for (n = peasants; n && luck; --n) { + int chances = 0; - if (luck > 0) { - --luck; - chances += PEASANTLUCK; - } - - while (chances--) { - if (rng_double() < peasant_growth_factor()) { - /* Only raise with 75% chance if peasants have - * reached 90% of maxpopulation */ - if (peasants / (float)maxp < 0.9 || chance(PEASANTFORCE)) { - ++births; - } - } - } + if (luck > 0) { + --luck; + chances += PEASANTLUCK; } - return births; + + while (chances--) { + if (rng_double() < factor) { + /* Only raise with 75% chance if peasants have + * reached 90% of maxpopulation */ + if (peasants / (float)maxp < 0.9 || chance(PEASANTFORCE)) { + ++births; + } + } + } + } + return births; } #endif @@ -336,8 +332,8 @@ static void peasants(region * r) luck = a->data.i * 1000; } - luck = peasant_luck_effect(peasants, luck, maxp); - ADDMSG(&r->msgs, msg_message("peasantluck_success", "births", luck)); + luck = peasant_luck_effect(peasants, luck, maxp, .5); + ADDMSG(&r->msgs, msg_message("peasantluck_success", "births", luck)); peasants += births + luck; } diff --git a/src/laws.test.c b/src/laws.test.c index 117e1fb3c..c6f6fb276 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1,5 +1,5 @@ #include -#include "laws.h" +#include "laws.c" #include #include @@ -692,6 +692,32 @@ static void test_reserve_self(CuTest *tc) { test_cleanup(); } +static void statistic_test(CuTest *tc, int peasants, int luck, int maxp, + float variance, int min_value, int max_value) +{ + int effect, i; + for (i = 0; i < 1000; ++i) { + effect = peasant_luck_effect(peasants, luck, maxp, variance); + CuAssertTrue(tc, min_value <= effect); + CuAssertTrue(tc, max_value >= effect); + } +} + +static void test_peasant_luck_effect(CuTest *tc) +{ + + set_param(&global.parameters, "rules.peasants.peasantluck.factor", "10"); + set_param(&global.parameters, "rules.peasants.growth.factor", "0.001"); + + statistic_test(tc, 100, 2, 1000, 0, 1, 1); + statistic_test(tc, 1000, 400, 1000, 0, 400 * 10 * 0.001 * .75, + 400 * 10 * 0.001 * .75); + statistic_test(tc, 1000, 1000, 2000, .5, 1, 501); + + set_param(&global.parameters, "rules.peasants.growth.factor", "1"); + statistic_test(tc, 1000, 1000, 1000, 0, 501, 501); +} + CuSuite *get_laws_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -722,6 +748,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_force_leave_buildings); SUITE_ADD_TEST(suite, test_force_leave_ships); SUITE_ADD_TEST(suite, test_force_leave_ships_on_ocean); + SUITE_ADD_TEST(suite, test_peasant_luck_effect); return suite; } diff --git a/src/util/rng.test.c b/src/util/rng.test.c index d73c23ef4..1740368fb 100644 --- a/src/util/rng.test.c +++ b/src/util/rng.test.c @@ -5,17 +5,17 @@ static void test_rng_round(CuTest * tc) { - double f; - int i,r; - for (i=0; i<1000; ++i) { - f = rng_double(); - r = RAND_ROUND(f); - CuAssertTrue(tc, f >= 0); - CuAssertTrue(tc, r <= (int) f+1); - CuAssertTrue(tc, r >= (int) f); - CuAssertTrue(tc, r == (int) r); - CuAssertTrue(tc, r == RAND_ROUND(r)); - } + double f; + int i, r; + for (i = 0; i < 1000; ++i) { + f = rng_double(); + r = RAND_ROUND(f); + CuAssertTrue(tc, f >= 0); + CuAssertTrue(tc, r <= (int ) f + 1); + CuAssertTrue(tc, r >= (int ) f); + CuAssertTrue(tc, r == (int ) r); + CuAssertTrue(tc, r == RAND_ROUND(r)); + } } CuSuite *get_rng_suite(void)