diff options
| author | Tyge Lovset <[email protected]> | 2023-02-01 08:38:45 +0100 |
|---|---|---|
| committer | Tyge Lovset <[email protected]> | 2023-02-01 08:38:45 +0100 |
| commit | 6ce6ef3307e52db5813d3c8d6a2cba52df06daf8 (patch) | |
| tree | 25af4be9fcd5e72778715b83ff312e157ca63b59 /misc/examples/random.c | |
| parent | b677a0c3950b8294ba6458e682a885351273ac08 (diff) | |
| download | STC-modified-6ce6ef3307e52db5813d3c8d6a2cba52df06daf8.tar.gz STC-modified-6ce6ef3307e52db5813d3c8d6a2cba52df06daf8.zip | |
Massive update from unsigned sizes and indices to signed.
Diffstat (limited to 'misc/examples/random.c')
| -rw-r--r-- | misc/examples/random.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/misc/examples/random.c b/misc/examples/random.c index 82214924..fc4576dd 100644 --- a/misc/examples/random.c +++ b/misc/examples/random.c @@ -5,10 +5,10 @@ int main() { const size_t N = 1000000000; - const uint64_t seed = time(NULL), range = 1000000; + const uint64_t seed = (uint64_t)time(NULL), range = 1000000; stc64_t rng = stc64_new(seed); - uint64_t sum; + int64_t sum; clock_t diff, before; printf("Compare speed of full and unbiased ranged random numbers...\n"); @@ -18,8 +18,8 @@ int main() sum += (uint32_t)stc64_rand(&rng); } diff = clock() - before; - printf("full range\t\t: %f secs, %" c_ZU ", avg: %f\n", - (float)diff / CLOCKS_PER_SEC, N, (double)sum / N); + 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); @@ -29,17 +29,17 @@ int main() sum += stc64_uniform(&rng, &dist1); // unbiased } diff = clock() - before; - printf("unbiased 0-%" PRIu64 "\t: %f secs, %" c_ZU ", avg: %f\n", - range, (float)diff/CLOCKS_PER_SEC, N, (double)sum / N); + 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); before = clock(); c_FORRANGE (N) { - sum += stc64_rand(&rng) % (range + 1); // biased + sum += (int64_t)(stc64_rand(&rng) % (range + 1)); // biased } diff = clock() - before; - printf("biased 0-%" PRIu64 " \t: %f secs, %" c_ZU ", avg: %f\n", - range, (float)diff / CLOCKS_PER_SEC, N, (double)sum / N); + printf("biased 0-%" PRIu64 " \t: %f secs, %" c_ZI ", avg: %f\n", + range, (float)diff / CLOCKS_PER_SEC, N, (float)sum / (float)N); } |
