diff options
| author | Tyge Løvset <[email protected]> | 2023-03-30 17:59:08 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-03-30 17:59:08 +0200 |
| commit | a0a290645828c88597efce80f6b0f5a958cefa89 (patch) | |
| tree | 53dc78071653b515a06a60baf4488a1b6d080b32 /misc/examples/random.c | |
| parent | 32df5677c9906661e91aad294e45a258e2eaab18 (diff) | |
| download | STC-modified-a0a290645828c88597efce80f6b0f5a958cefa89.tar.gz STC-modified-a0a290645828c88597efce80f6b0f5a958cefa89.zip | |
Added crand.h - Alternative API to crandom.h, which will be deprecated.
Diffstat (limited to 'misc/examples/random.c')
| -rw-r--r-- | misc/examples/random.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/misc/examples/random.c b/misc/examples/random.c index e27279a0..ea9c483e 100644 --- a/misc/examples/random.c +++ b/misc/examples/random.c @@ -1,12 +1,12 @@ #include <stdio.h> #include <time.h> -#include <stc/crandom.h> +#include <stc/crand.h> int main() { const size_t N = 1000000000; const uint64_t seed = (uint64_t)time(NULL), range = 1000000; - stc64_t rng = stc64_new(seed); + crand_t rng = crand_init(seed); int64_t sum; clock_t diff, before; @@ -15,28 +15,28 @@ int main() sum = 0; before = clock(); c_forrange (N) { - sum += (uint32_t)stc64_rand(&rng); + sum += (uint32_t)crand_u64(&rng); } diff = clock() - before; printf("full range\t\t: %f secs, %" c_ZI ", avg: %f\n", (float)diff / CLOCKS_PER_SEC, N, (float)sum / (float)N); - stc64_uniform_t dist1 = stc64_uniform_new(0, range); - rng = stc64_new(seed); + crand_unif_t dist1 = crand_unif_init(0, range); + rng = crand_init(seed); sum = 0; before = clock(); c_forrange (N) { - sum += stc64_uniform(&rng, &dist1); // unbiased + sum += crand_unif(&rng, &dist1); // unbiased } diff = clock() - before; printf("unbiased 0-%" PRIu64 "\t: %f secs, %" c_ZI ", avg: %f\n", range, (float)diff/CLOCKS_PER_SEC, N, (float)sum / (float)N); sum = 0; - rng = stc64_new(seed); + rng = crand_init(seed); before = clock(); c_forrange (N) { - sum += (int64_t)(stc64_rand(&rng) % (range + 1)); // biased + sum += (int64_t)(crand_u64(&rng) % (range + 1)); // biased } diff = clock() - before; printf("biased 0-%" PRIu64 " \t: %f secs, %" c_ZI ", avg: %f\n", |
