diff options
| author | Tyge Løvset <[email protected]> | 2020-12-28 18:18:48 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-12-28 18:18:48 +0100 |
| commit | 74a75b3a8d155ea155358674d3bf8251658183a5 (patch) | |
| tree | 19886986b9ce6943b826311cda40f67ebc8dd7b1 /examples | |
| parent | 83b7be31a1d0fc0be4e013dbfc97bb6cdc3600db (diff) | |
| download | STC-modified-74a75b3a8d155ea155358674d3bf8251658183a5.tar.gz STC-modified-74a75b3a8d155ea155358674d3bf8251658183a5.zip | |
Reverted crand.h API back to rename crand_* to stc64_*, and crand_next() -> stc64_rand().
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/birthday.c | 8 | ||||
| -rw-r--r-- | examples/ex_gaussian.c | 6 | ||||
| -rw-r--r-- | examples/list.c | 6 | ||||
| -rw-r--r-- | examples/priority.c | 8 | ||||
| -rw-r--r-- | examples/queue.c | 10 | ||||
| -rw-r--r-- | examples/random.c | 12 |
6 files changed, 25 insertions, 25 deletions
diff --git a/examples/birthday.c b/examples/birthday.c index a2856a3f..dc94fa53 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -15,11 +15,11 @@ static void test_repeats(void) const static uint64_t mask = (1ull << BITS) - 1;
printf("birthday paradox: value range: 2^%d, testing repeats of 2^%d values\n", BITS, BITS_TEST);
- crand_t rng = crand_init(seed);
+ stc64_t rng = stc64_init(seed);
cmap_ic m = cmap_ic_init();
cmap_ic_reserve(&m, N);
c_forrange (i, N) {
- uint64_t k = crand_next(&rng) & mask;
+ uint64_t k = stc64_rand(&rng) & mask;
int v = ++cmap_ic_emplace(&m, k, 0).first->second;
if (v > 1) printf("repeated value %llx (%d) at 2^%d\n", k, v, (int) log2(i));
}
@@ -32,12 +32,12 @@ void test_distribution(void) {
enum {BITS = 26};
printf("distribution test: 2^%d values\n", BITS);
- crand_t rng = crand_init(seed);
+ stc64_t rng = stc64_init(seed);
const size_t N = 1ull << BITS ;
cmap_x map = cmap_x_init();
c_forrange (N) {
- uint64_t k = crand_next(&rng);
+ uint64_t k = stc64_rand(&rng);
++cmap_x_emplace(&map, k & 0xf, 0).first->second;
}
diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c index 5357a2f8..a5137614 100644 --- a/examples/ex_gaussian.c +++ b/examples/ex_gaussian.c @@ -25,13 +25,13 @@ int main() // Setup random engine with normal distribution.
uint64_t seed = time(NULL);
- crand_t rng = crand_init(seed);
- crand_normalf_t dist = crand_normalf_init(Mean, StdDev);
+ stc64_t rng = stc64_init(seed);
+ stc64_normalf_t dist = stc64_normalf_init(Mean, StdDev);
// Create histogram map
cmap_i mhist = cmap_i_init();
for (size_t i = 0; i < N; ++i) {
- int index = (int) round( crand_normalf(&rng, &dist) );
+ int index = (int) round( stc64_normalf(&rng, &dist) );
cmap_i_emplace(&mhist, index, 0).first->second += 1;
}
diff --git a/examples/list.c b/examples/list.c index d65da22b..9d6e8d89 100644 --- a/examples/list.c +++ b/examples/list.c @@ -9,11 +9,11 @@ int main() { const int n = 2000000;
clist_fx list = clist_inits;
- crand_t rng = crand_init(1234);
- crand_uniformf_t dist = crand_uniformf_init(100.0f, n);
+ stc64_t rng = stc64_init(1234);
+ stc64_uniformf_t dist = stc64_uniformf_init(100.0f, n);
int m = 0;
c_forrange (i, int, n)
- clist_fx_push_back(&list, crand_uniformf(&rng, &dist)), ++m;
+ clist_fx_push_back(&list, stc64_uniformf(&rng, &dist)), ++m;
double sum = 0.0;
printf("sumarize %d:\n", m);
c_foreach (i, clist_fx, list)
diff --git a/examples/priority.c b/examples/priority.c index 4eb762ec..4eceb29f 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -11,19 +11,19 @@ using_cpque(i, cvec_i, >); // min-heap (increasing values) int main() {
size_t N = 10000000;
- crand_t rng = crand_init(time(NULL));
- crand_uniform_t dist = crand_uniform_init(0, N * 10);
+ stc64_t rng = stc64_init(time(NULL));
+ stc64_uniform_t dist = stc64_uniform_init(0, N * 10);
cpque_i heap = cpque_i_init();
// Push ten million random numbers to priority queue
c_forrange (N)
- cpque_i_push(&heap, crand_uniform(&rng, &dist));
+ cpque_i_push(&heap, stc64_uniform(&rng, &dist));
// push some negative numbers too.
c_push_items(&heap, cpque_i, {-231, -32, -873, -4, -343});
c_forrange (N)
- cpque_i_push(&heap, crand_uniform(&rng, &dist));
+ cpque_i_push(&heap, stc64_uniform(&rng, &dist));
// Extract the hundred smallest.
diff --git a/examples/queue.c b/examples/queue.c index d1eae6bc..bf287e7c 100644 --- a/examples/queue.c +++ b/examples/queue.c @@ -13,20 +13,20 @@ using_cqueue(i, cdeq_i); int main() {
int n = 100000000;
- crand_uniform_t dist;
- crand_t rng = crand_init(1234);
- dist = crand_uniform_init(0, n);
+ stc64_uniform_t dist;
+ stc64_t rng = stc64_init(1234);
+ dist = stc64_uniform_init(0, n);
cqueue_i queue = cqueue_i_init();
// Push ten million random numbers onto the queue.
c_forrange (n)
- cqueue_i_push(&queue, crand_uniform(&rng, &dist));
+ cqueue_i_push(&queue, stc64_uniform(&rng, &dist));
// Push or pop on the queue ten million times
printf("%d\n", n);
c_forrange (n) { // range uses initial n only.
- int r = crand_uniform(&rng, &dist);
+ int r = stc64_uniform(&rng, &dist);
if (r & 1)
++n, cqueue_i_push(&queue, r);
else
diff --git a/examples/random.c b/examples/random.c index 94a68607..7325e023 100644 --- a/examples/random.c +++ b/examples/random.c @@ -9,16 +9,16 @@ int main() enum {R = 30};
const size_t N = 1000000000;
uint64_t seed = 1234; // time(NULL);
- crand_t rng = crand_init(seed);
+ stc64_t rng = stc64_init(seed);
uint64_t sum = 0;
- crand_normalf_t dist2 = crand_normalf_init(R / 2.0, R / 6.0);
+ stc64_normalf_t dist2 = stc64_normalf_init(R / 2.0, R / 6.0);
size_t N2 = 10000000;
int hist[R] = {0};
sum = 0;
c_forrange (N2) {
- int n = round((crand_normalf(&rng, &dist2) + 0.5));
+ int n = round((stc64_normalf(&rng, &dist2) + 0.5));
sum += n;
if (n >= 0 && n < R) ++hist[n];
}
@@ -33,16 +33,16 @@ int main() sum = 0;
before = clock();
c_forrange (N) {
- sum += crand_next(&rng);
+ sum += stc64_rand(&rng);
}
diff = clock() - before;
printf("random : %f secs, %zu %f\n", (float) diff / CLOCKS_PER_SEC, N, (double) sum / N);
- crand_uniform_t dist1 = crand_uniform_init(0, 1000);
+ stc64_uniform_t dist1 = stc64_uniform_init(0, 1000);
sum = 0;
before = clock();
c_forrange (N) {
- sum += crand_uniform(&rng, &dist1);
+ sum += stc64_uniform(&rng, &dist1);
}
diff = clock() - before;
printf("uniform: %f secs, %zu %f\n", (float) diff / CLOCKS_PER_SEC, N, (double) sum / N);
|
