You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#define _RNGXX_INLINE_ONLY
|
|
#include <rngxx.h>
|
|
|
|
static int next(rng_t* rng, const int* min, const int* max)
|
|
{
|
|
int output;
|
|
if(rng_next_tyb(rng, &output, RNG_TY_INT32, RNG_TYQ_SIGNED, min, max)) return output;
|
|
|
|
fprintf(stderr, "next<int>() failed\n");
|
|
exit(-1);
|
|
}
|
|
|
|
#define TREF(x) ( (const __typeof(x)[]){ (x) } )
|
|
|
|
int main()
|
|
{
|
|
rng_dyn_ctor_ref rcref = rng_ctor_ref("crand");
|
|
rng_ctor_fn rctor = rng_ctor("crand");
|
|
|
|
rng_t* engine = NULL;
|
|
if(rctor) {
|
|
printf("constructing direct\n");
|
|
engine = rctor(TREF((u64)time(NULL)));
|
|
} else {
|
|
printf("constructing through ref\n");
|
|
engine = rng_ctor_call(rcref, TREF((u64)time(NULL)));
|
|
}
|
|
if(!engine) {
|
|
printf("fallback to `rng_new_named()`\n");
|
|
engine = rng_new_named("crand", TREF((u64)time(NULL))); //rng_new(rng_kind_crand, (const u64[]){ time(null) });
|
|
}
|
|
if(!engine) {
|
|
printf("fallback to static init\n");
|
|
engine = rng_new(RNG_KIND_CRAND, (const u64[]){ time(NULL) });
|
|
}
|
|
if(!engine) {
|
|
fprintf(stderr, "failed to create engine\n");
|
|
return 1;
|
|
}
|
|
printf("%d %d %d\n", next(engine, NULL, TREF(100)), next(engine, TREF(10), TREF(20)), next(engine, NULL, NULL));
|
|
printf("%ld\n", rng_next_i64(engine, NULL, NULL));
|
|
printf("%lf\n", rng_next_f64(engine, TREF(1.0), TREF(100.0)));
|
|
printf("%d\n", rng_next_bool(engine));
|
|
rng_free(engine);
|
|
return 0;
|
|
}
|