forked from Telodendria/Telodendria
Jordan Bancino
d933d12e1b
This implementation is loosely inspired by the original paper on the Mersenne Twister, and borrows code from a public-domain implementation of it, adapting it to fit the style of Telodendria's code, and fixing a few bugs regarding the size of the data type used. Neither C nor POSIX provide a good, thread-safe pseudorandom number generator. The OpenBSD linker started complaining about the use of rand_r(), and no standard alternative presented itself as worthy of consideration, so I finally decided it was time to roll my own PRNG.
25 lines
408 B
C
25 lines
408 B
C
#include <Int.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#define ASSERT_SIZE(type, size) \
|
|
if ((sizeof(type) * 8) != size) \
|
|
{ \
|
|
fputs(#type " is not " #size " bits.\n", stderr); \
|
|
return 1; \
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
ASSERT_SIZE(Int8, 8);
|
|
ASSERT_SIZE(UInt8, 8);
|
|
|
|
ASSERT_SIZE(Int16, 16);
|
|
ASSERT_SIZE(UInt16, 16);
|
|
|
|
ASSERT_SIZE(Int32, 32);
|
|
ASSERT_SIZE(UInt32, 32);
|
|
|
|
return 0;
|
|
}
|