aboutsummaryrefslogtreecommitdiff
path: root/km-rand.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-02-04 11:18:30 -0500
committerPaul Duncan <pabs@pablotron.org>2019-02-04 11:18:30 -0500
commitf4a38b43d43f9395d6042d234a5e0ada7455ace1 (patch)
tree6357eac32d23a1fcaad5f4a8dd457a78f286855a /km-rand.c
parent33e7c5bfdb9099e915876b8dbf6d3129459c2bc3 (diff)
downloadkmeans-f4a38b43d43f9395d6042d234a5e0ada7455ace1.tar.bz2
kmeans-f4a38b43d43f9395d6042d234a5e0ada7455ace1.zip
refactor random names
Diffstat (limited to 'km-rand.c')
-rw-r--r--km-rand.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/km-rand.c b/km-rand.c
index 1410861..bb3a2cc 100644
--- a/km-rand.c
+++ b/km-rand.c
@@ -4,22 +4,22 @@
// fill buffer with N random floats
bool
-km_rand_fill(
+km_rand_get_floats(
km_rand_t * const rs,
const size_t num_floats,
float * const floats
) {
- return rs->cbs->fill(rs, num_floats, floats);
+ return rs->cbs->get_floats(rs, num_floats, floats);
}
// fill buffer with N random size_ts
bool
-km_rand_fill_sizes(
+km_rand_get_sizes(
km_rand_t * const rs,
const size_t num_sizes,
size_t * const sizes
) {
- return rs->cbs->fill_sizes(rs, num_sizes, sizes);
+ return rs->cbs->get_sizes(rs, num_sizes, sizes);
}
// finalize random source
@@ -32,18 +32,18 @@ km_rand_fini(
}
}
-// fill callback for system random source
+// libc random source get_floats
static bool
-system_on_fill(
+rand_libc_get_floats(
km_rand_t * const rs,
- const size_t num_floats,
- float * const floats
+ const size_t num_vals,
+ float * const vals
) {
UNUSED(rs);
- // generate random cluster centers
- for (size_t i = 0; i < num_floats; i++) {
- floats[i] = 1.0 * rand() / RAND_MAX;
+ // generate results
+ for (size_t i = 0; i < num_vals; i++) {
+ vals[i] = 1.0 * rand() / RAND_MAX;
}
// return success
@@ -52,16 +52,16 @@ system_on_fill(
// fill sizes callback for system random source
static bool
-system_on_fill_sizes(
+rand_libc_get_sizes(
km_rand_t * const rs,
- const size_t num_sizes,
- size_t * const sizes
+ const size_t num_vals,
+ size_t * const vals
) {
UNUSED(rs);
- // generate random size_ts
- for (size_t i = 0; i < num_sizes; i++) {
- sizes[i] = rand();
+ // generate results
+ for (size_t i = 0; i < num_vals; i++) {
+ vals[i] = rand();
}
// return success
@@ -70,17 +70,17 @@ system_on_fill_sizes(
// system random source callbacks
static const km_rand_cbs_t
-SYSTEM_CBS = {
- .fill = system_on_fill,
- .fill_sizes = system_on_fill_sizes,
+RAND_LIBC_CBS = {
+ .get_floats = rand_libc_get_floats,
+ .get_sizes = rand_libc_get_sizes,
.fini = NULL,
};
// init system random source (uses system rand())
void
-km_rand_init_system(
+km_rand_init_libc(
km_rand_t * const rs
) {
- rs->cbs = &SYSTEM_CBS;
+ rs->cbs = &RAND_LIBC_CBS;
rs->data = NULL;
}