void lwmsg_session_generate_cookie( LWMsgSessionCookie* cookie ) { mt m; uint32_t seed[3]; uint32_t s; int i; LWMsgTime now; lwmsg_time_now(&now); /* Add in 32 bits of data from the address of the cookie */ seed[0] = (uint32_t) (size_t) cookie; /* Add in 32 bits of data from the current pid */ seed[1] = (uint32_t) getpid(); /* Add in 32 bits of data from the current time */ seed[2] = (uint32_t) now.microseconds; mt_init_by_array(&m, seed, sizeof(seed) / sizeof(*seed)); for (i = 0; i < sizeof(cookie->bytes); i += sizeof(s)) { s = mt_genrand_int32(&m); memcpy(cookie->bytes + i, &s, sizeof(s)); } }
void main(void){ mt_t mt; uint32_t init[4] = {61731, 24903, 614, 42143}; unsigned int length = 4; mt_init_by_array(&mt, init, length); for (int i = 0; i < 2000; i++) { printf("%.16f ", mt_genrand_res53(&mt)); if (i%5==4) printf("\n"); } }