From aa74bd04f66217ff4d617924630b13d721578159 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 3 Feb 2019 16:12:04 -0500 Subject: add km_set_init_rand_points() --- km-rand.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'km-rand.c') diff --git a/km-rand.c b/km-rand.c index fcc6a74..1410861 100644 --- a/km-rand.c +++ b/km-rand.c @@ -12,6 +12,16 @@ km_rand_fill( return rs->cbs->fill(rs, num_floats, floats); } +// fill buffer with N random size_ts +bool +km_rand_fill_sizes( + km_rand_t * const rs, + const size_t num_sizes, + size_t * const sizes +) { + return rs->cbs->fill_sizes(rs, num_sizes, sizes); +} + // finalize random source void km_rand_fini( @@ -40,11 +50,30 @@ system_on_fill( return true; } +// fill sizes callback for system random source +static bool +system_on_fill_sizes( + km_rand_t * const rs, + const size_t num_sizes, + size_t * const sizes +) { + UNUSED(rs); + + // generate random size_ts + for (size_t i = 0; i < num_sizes; i++) { + sizes[i] = rand(); + } + + // return success + return true; +} + // system random source callbacks static const km_rand_cbs_t SYSTEM_CBS = { - .fill = system_on_fill, - .fini = NULL, + .fill = system_on_fill, + .fill_sizes = system_on_fill_sizes, + .fini = NULL, }; // init system random source (uses system rand()) -- cgit v1.2.3