#include <freeradius-devel/util/acutest.h>
#include <freeradius-devel/util/time.h>
+#include <freeradius-devel/util/rand.h>
#include "heap.c"
heap_thing *array;
int left;
int ret;
-
+ fr_fast_rand_t rand_ctx;
static bool done_init = false;
if (!done_init) {
- srand((unsigned int)time(NULL));
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
done_init = true;
}
/*
* Initialise random values
*/
- for (i = 0; i < HEAP_TEST_SIZE; i++) array[i].data = rand() % 65537;
+ for (i = 0; i < HEAP_TEST_SIZE; i++) array[i].data = fr_fast_rand(&rand_ctx) % 65537;
#if 0
for (i = 0; i < HEAP_TEST_SIZE; i++) {
int data = 0;
unsigned int count = 0;
int ret;
-
+ fr_fast_rand_t rand_ctx;
static bool done_init = false;
if (!done_init) {
- srand((unsigned int)time(NULL));
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
done_init = true;
}
/*
* Initialise random values
*/
- for (i = 0; i < HEAP_TEST_SIZE; i++) array[i].data = rand() % 65537;
+ for (i = 0; i < HEAP_TEST_SIZE; i++) array[i].data = fr_fast_rand(&rand_ctx) % 65537;
TEST_CASE("insertions");
for (i = 0; i < HEAP_TEST_SIZE; i++) {
int inserted, removed;
int ret;
fr_time_t start_insert, start_remove, start_swap, end;
-
+ fr_fast_rand_t rand_ctx;
static bool done_init = false;
if (!done_init) {
- srand((unsigned int)time(NULL));
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
done_init = true;
}
/*
* Initialise random values
*/
- for (i = 0; i < HEAP_CYCLE_SIZE; i++) array[i].data = rand() % 65537;
+ for (i = 0; i < HEAP_CYCLE_SIZE; i++) array[i].data = fr_fast_rand(&rand_ctx) % 65537;
start_insert = fr_time();
TEST_CASE("insertions");
fr_lst_t *lst;
fr_heap_t *hp;
lst_thing *lst_array, *hp_array;
+ fr_fast_rand_t rand_ctx;
static bool done_init = false;
int ret;
lst_thing *from_lst, *from_hp;
if (!done_init) {
- srand((unsigned int) time(NULL));
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
done_init = true;
}
/*
* Initialise random values
*/
- for (unsigned int i = 0; i < 2 * INITIAL_CAPACITY; i++) lst_array[i].data = hp_array[i].data = rand() % 65537;
+ for (unsigned int i = 0; i < 2 * INITIAL_CAPACITY; i++) {
+ lst_array[i].data = hp_array[i].data = fr_fast_rand(&rand_ctx) % 65537;
+ }
/* Add the first INITIAL_CAPACITY values to lst and to hp */
TEST_CASE("partial fill");
{
fr_lst_t *lst = NULL;
lst_thing *array = NULL;
+ fr_fast_rand_t rand_ctx;
static bool done_init = false;
int insert_count = 0;
if (!done_init) {
- srand((unsigned int) time(NULL));
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
done_init = true;
}
array = calloc(BURN_IN_OPS, sizeof(lst_thing));
- for (unsigned int i = 0; i < BURN_IN_OPS; i++) array[i].data = rand() % 65537;
+ for (unsigned int i = 0; i < BURN_IN_OPS; i++) array[i].data = fr_fast_rand(&rand_ctx) % 65537;
/* Make init small to exercise growing the pivot stack. */
lst = fr_lst_alloc(NULL, lst_cmp, lst_thing, idx, 32);
minmax_heap_thing *array;
int left;
int ret;
-
+ fr_fast_rand_t rand_ctx;
static bool done_init = false;
if (!done_init) {
- unsigned int seed = /* 1634677281 */ (unsigned int) time(NULL);
-
- // fprintf(stderr, "seed %u\n", seed);
- srand(seed);
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
done_init = true;
}
/*
* Initialise random values
*/
- for (i = 0; i < MINMAX_HEAP_TEST_SIZE; i++) array[i].data = rand() % 65537;
+ for (i = 0; i < MINMAX_HEAP_TEST_SIZE; i++) array[i].data = fr_fast_rand(&rand_ctx) % 65537;
TEST_CASE("insertions");
for (i = 0; i < MINMAX_HEAP_TEST_SIZE; i++) {
{
fr_minmax_heap_t *hp = NULL;
minmax_heap_thing *array = NULL;
+ fr_fast_rand_t rand_ctx;
static bool done_init = false;
int insert_count = 0;
if (!done_init) {
- srand((unsigned int) time(0));
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
done_init = true;
}
array = calloc(BURN_IN_OPS, sizeof(minmax_heap_thing));
- for (unsigned int i = 0; i < BURN_IN_OPS; i++) array[i].data = rand() % 65537;
+ for (unsigned int i = 0; i < BURN_IN_OPS; i++) array[i].data = fr_fast_rand(&rand_ctx) % 65537;
hp = fr_minmax_heap_alloc(NULL, minmax_heap_cmp, minmax_heap_thing, idx, 0);
unsigned int data;
unsigned int count;
int ret;
-
+ fr_fast_rand_t rand_ctx;
static bool done_init = false;
if (!done_init) {
- srand((unsigned int)time(NULL));
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
done_init = true;
}
/*
* Initialise random values
*/
- for (i = 0; i < MINMAX_HEAP_TEST_SIZE; i++) array[i].data = rand() % 65537;
+ for (i = 0; i < MINMAX_HEAP_TEST_SIZE; i++) array[i].data = fr_fast_rand(&rand_ctx) % 65537;
TEST_CASE("insertions for min");
for (i = 0; i < MINMAX_HEAP_TEST_SIZE; i++) {
int inserted, removed;
int ret;
fr_time_t start_insert, start_remove, start_swap, end;
-
+ fr_fast_rand_t rand_ctx;
static bool done_init = false;
if (!done_init) {
- srand((unsigned int)time(NULL));
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
done_init = true;
}
/*
* Initialise random values
*/
- for (i = 0; i < MINMAX_HEAP_CYCLE_SIZE; i++) array[i].data = rand() % 65537;
+ for (i = 0; i < MINMAX_HEAP_CYCLE_SIZE; i++) array[i].data = fr_fast_rand(&rand_ctx) % 65537;
start_insert = fr_time();
TEST_CASE("insertions");
#include <freeradius-devel/util/dict_test.h>
#include <freeradius-devel/server/base.h>
+#include <freeradius-devel/util/rand.h>
/*
* Global variables
fr_time_t start, end;
fr_time_delta_t used = fr_time_delta_wrap(0);
size_t input_count = talloc_array_length(source_vps);
+ fr_fast_rand_t rand_ctx;
fr_pair_list_init(&test_vps);
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
/*
* Only use up to the number of pairs needed from the source to maintain ratio
*/
for (i = 0; i < reps; i++) {
for (j = 0; j < len; j++) {
- int idx = rand() % input_count;
+ int idx = fr_fast_rand(&rand_ctx) % input_count;
new_vp = fr_pair_copy(autofree, source_vps[idx]);
start = fr_time();
fr_pair_append(&test_vps, new_vp);
fr_time_delta_t used = fr_time_delta_wrap(0);
fr_dict_attr_t const *da;
size_t input_count = talloc_array_length(source_vps);
+ fr_fast_rand_t rand_ctx;
fr_pair_list_init(&test_vps);
if (input_count > len) input_count = len;
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
/*
* Initialise the test list
*/
for (i = 0; i < len; i++) {
- int idx = rand() % input_count;
+ int idx = fr_fast_rand(&rand_ctx) % input_count;
new_vp = fr_pair_copy(autofree, source_vps[idx]);
fr_pair_append(&test_vps, new_vp);
}
*/
for (i = 0; i < reps; i++) {
for (j = 0; j < len; j++) {
- int idx = rand() % input_count;
+ int idx = fr_fast_rand(&rand_ctx) % input_count;
da = source_vps[idx]->da;
start = fr_time();
(void) fr_pair_find_by_da_idx(&test_vps, da, 0);
fr_time_delta_t used = fr_time_delta_wrap(0);
fr_dict_attr_t const *da;
size_t input_count = talloc_array_length(source_vps);
+ fr_fast_rand_t rand_ctx;
fr_pair_list_init(&test_vps);
if (input_count > len) input_count = len;
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
/*
* Initialise the test list
*/
for (i = 0; i < len; i++) {
- int idx = rand() % input_count;
+ int idx = fr_fast_rand(&rand_ctx) % input_count;
new_vp = fr_pair_copy(autofree, source_vps[idx]);
fr_pair_append(&test_vps, new_vp);
}
nth_item = perc == 0 ? 1 : (unsigned int)(len * perc / 100);
for (i = 0; i < reps; i++) {
for (j = 0; j < len; j++) {
- int idx = rand() % input_count;
+ int idx = fr_fast_rand(&rand_ctx) % input_count;
da = source_vps[idx]->da;
start = fr_time();
fr_time_t start, end;
fr_time_delta_t used = fr_time_delta_wrap(0);
size_t input_count = talloc_array_length(source_vps);
+ fr_fast_rand_t rand_ctx;
fr_pair_list_init(&test_vps);
if (input_count > len) input_count = len;
+ rand_ctx.a = fr_rand();
+ rand_ctx.b = fr_rand();
for (i = 0; i < reps; i++) {
for (j = 0; j < len; j++) {
- int idx = rand() % input_count;
+ int idx = fr_fast_rand(&rand_ctx) % input_count;
new_vp = fr_pair_copy(autofree, source_vps[idx]);
fr_pair_append(&test_vps, new_vp);
}