uint32_t linear_congruential_generator(uint32_t s_seed) { return ((int)((((uint64_t)s_seed) * ((uint64_t)0x10A860C1 /* 279470273 */)) % ((uint64_t)0xFFFFFFFB /* 1<<32 - 5 */))); }
#define def_rand_max (~((uint32_t)0u)) #define def_rand_const_i ((uint32_t)1u) /* 또는 time((time_t)0u) */ #define def_rand_const_a ((uint32_t)1103515245u) /* 또는 22695477 */ #define def_rand_const_c ((uint32_t)12345u) /* 또는 1 */ static uint32_t g_rand_value = def_rand_const_i ; int hwport_rand(void) { g_rand_value = (g_rand_value * def_rand_const_a) + def_rand_const_c ; return (int)(g_rand_value >> 16) & def_rand_max; /* 또는 (((g_rand_value >> 16) | (g_rand_value << 16)) >> 1) */ } void hwport_srand(unsigned int s_seed) { g_rand_value = (uint32_t)s_seed; }