#include "../tdkpin_random.h" #include uint32_t g_borland_random_seed; static uint32_t expected_next(uint32_t seed) { return seed * 0x08088405u + 1u; } int main(void) { g_borland_random_seed = 0x12345678; uint32_t first = expected_next(g_borland_random_seed); assert(borland_next_random() == first); uint32_t second = expected_next(first); uint16_t expected_below = (uint16_t)(((uint64_t)second * 3800) >> 32); assert(borland_random_below(3800) == expected_below); uint32_t third = expected_next(second); int8_t expected_exponent = 0; if (third != 0) { expected_exponent = -128; while ((third & 0x80000000u) == 0) { third <<= 1; expected_exponent--; } } assert(borland_random_exponent() == expected_exponent); g_borland_random_seed = 7; (void)borland_random_below(0); assert(g_borland_random_seed == expected_next(7)); g_borland_random_seed = 0xfedcba98; uint32_t unit_seed = expected_next(g_borland_random_seed); assert(borland_random_unit_interval() == (double)unit_seed / 4294967296.0); assert(borland_random_unit_interval() >= 0.0 && borland_random_unit_interval() < 1.0); win16_reset_segment_bindings(); win16_set_dos_time_words(0x33441122); borland_seed_random_from_dos_time(); assert(g_borland_random_seed == 0x33441122); return 0; }