-rw-r--r-- 1402 cryptattacktester-20231020/randomtest.cpp raw
#include <cassert> #include <algorithm> #include "random.h" using namespace std; static void test_repeatable() { for (bigint seed = -32;seed <= 32;++seed) { random_seed(seed); bool b = random_bool(); int i = random_int(); unsigned int ui = random_uint(); long l = random_long(); unsigned long ul = random_ulong(); long long ll = random_longlong(); unsigned long long ull = random_ulonglong(); bigint below = random_bigint_below(31415); cout << "repeatable " << seed << ' ' << b << ' ' << i << ' ' << ui << ' ' << l << ' ' << ul << ' ' << ll << ' ' << ull << ' ' << below << '\n'; random_seed(seed); assert(b == random_bool()); assert(i == random_int()); assert(ui == random_uint()); assert(l == random_long()); assert(ul == random_ulong()); assert(ll == random_longlong()); assert(ull == random_ulonglong()); assert(below == random_bigint_below(31415)); } } static bool cmp(unsigned long long &a,unsigned long long &b) { return a < b; } static void test_distinct() { random_seed(); unsigned long long x[1000]; for (bigint loop = 0;loop < 1000;++loop) x[loop] = random_ulonglong(); sort(x,x+1000,cmp); for (bigint loop = 1;loop < 1000;++loop) assert(x[loop-1] < x[loop]); cout << "distinct " << x[0] << ' ' << x[999] << '\n'; } int main() { test_repeatable(); test_distinct(); return 0; }