summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/algorithms/random.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/examples/algorithms/random.c')
-rw-r--r--misc/examples/algorithms/random.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/misc/examples/algorithms/random.c b/misc/examples/algorithms/random.c
index b7c0f277..ccd0711d 100644
--- a/misc/examples/algorithms/random.c
+++ b/misc/examples/algorithms/random.c
@@ -4,11 +4,11 @@
int main(void)
{
- const int N = 1000000000;
+ long long N = 1000000000;
const uint64_t seed = (uint64_t)time(NULL), range = 1000000;
crand_t rng = crand_init(seed);
- int64_t sum;
+ long long sum;
clock_t diff, before;
printf("Compare speed of full and unbiased ranged random numbers...\n");
@@ -18,19 +18,19 @@ int main(void)
sum += (uint32_t)crand_u64(&rng);
}
diff = clock() - before;
- printf("full range\t\t: %f secs, %d, avg: %f\n",
- (double)diff/CLOCKS_PER_SEC, N, (double)sum/N);
+ printf("full range\t\t: %f secs, %lld, avg: %f\n",
+ (double)diff/CLOCKS_PER_SEC, N, (double)(sum/N));
- crand_unif_t dist1 = crand_unif_init(0, range);
+ crand_uniform_t dist1 = crand_uniform_init(0, range);
rng = crand_init(seed);
sum = 0;
before = clock();
c_forrange (N) {
- sum += crand_unif(&rng, &dist1); // unbiased
+ sum += crand_uniform(&rng, &dist1); // unbiased
}
diff = clock() - before;
- printf("unbiased 0-%" PRIu64 "\t: %f secs, %d, avg: %f\n",
- range, (double)diff/CLOCKS_PER_SEC, N, (double)sum/N);
+ printf("unbiased 0-%" PRIu64 "\t: %f secs, %lld, avg: %f\n",
+ range, (double)diff/CLOCKS_PER_SEC, N, (double)(sum/N));
sum = 0;
rng = crand_init(seed);
@@ -39,7 +39,7 @@ int main(void)
sum += (int64_t)(crand_u64(&rng) % (range + 1)); // biased
}
diff = clock() - before;
- printf("biased 0-%" PRIu64 " \t: %f secs, %d, avg: %f\n",
- range, (double)diff/CLOCKS_PER_SEC, N, (double)sum/N);
+ printf("biased 0-%" PRIu64 " \t: %f secs, %lld, avg: %f\n",
+ range, (double)diff/CLOCKS_PER_SEC, N, (double)(sum/N));
}