diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b115c5..cfc2286 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ set(SOURCES src/stdlib/exit.c src/stdlib/fpconv.c src/stdlib/intconv.c + src/stdlib/rand.c src/stdlib/sizes.c # string src/string/core.c diff --git a/include/ft/all-tests.h b/include/ft/all-tests.h index d2f615c..18c6fb4 100644 --- a/include/ft/all-tests.h +++ b/include/ft/all-tests.h @@ -34,6 +34,7 @@ extern ft_test ft_stdlib_sizes; extern ft_test ft_stdlib_llconv; extern ft_test ft_stdlib_lconv; extern ft_test ft_stdlib_fpconv; +extern ft_test ft_stdlib_rand; extern ft_test ft_stdlib_exit; extern ft_test ft_stdlib__Exit; extern ft_test ft_stdlib_abort; diff --git a/src/main.c b/src/main.c index 2bcf5d4..cce8e57 100644 --- a/src/main.c +++ b/src/main.c @@ -51,6 +51,7 @@ ft_list headers_libc[] = { &ft_stdlib_llconv, &ft_stdlib_lconv, &ft_stdlib_fpconv, + &ft_stdlib_rand, &ft_stdlib_exit, &ft_stdlib__Exit, &ft_stdlib_abort, diff --git a/src/stdlib/rand.c b/src/stdlib/rand.c new file mode 100644 index 0000000..9c53c71 --- /dev/null +++ b/src/stdlib/rand.c @@ -0,0 +1,30 @@ +#include +#include +#include + +void _ft_stdlib_rand(ft_test *t) +{ + srand(0xdeadbeef); + ft_assert(t, rand() == 0x797dd849); + ft_assert(t, rand() == 0x02687112); + ft_assert(t, rand() == 0x2222a00d); + ft_assert(t, rand() == 0x67c2ff94); + + unsigned int seed = 0xc0ffee; + srand(seed); + ft_log(t, "Seed: %#x\n\n", seed); + + for(int i = 0; i < 8; i++) { + int i1 = rand(); + int i2 = rand(); + int i3 = rand(); + int i4 = rand(); + + ft_log(t, " %08X %08X %08X %08X\n", i1, i2, i3, i4); + } +} + +ft_test ft_stdlib_rand = { + .name = "TinyMT random numbers", + .function = _ft_stdlib_rand, +};