C API basic test

Fortune for rngxx's current commit: Blessing − 吉
capi
Avril 3 years ago
parent 29187574be
commit 9ebf0384a5

1
.gitignore vendored

@ -2,5 +2,6 @@ obj/
vgcore.*
*-release
*-debug
*-test
*.so*
*.a

@ -4,15 +4,15 @@ PROJECT=rngxx
AUTHOR=Avril (Flanchan) <flanchan@cumallover.me>
VERSION_MAJOR=0
VERSION_MINOR=0
VERSION_MINOR=1
VERSION=$(VERSION_MAJOR).$(VERSION_MINOR)
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
SRC_C = $(wildcard src/*.c)
SRC_CXX = $(wildcard src/*.cpp)
SRC_C = $(wildcard src/*.c) $(wildcard src/rng/*.c)
SRC_CXX = $(wildcard src/*.cpp) $(wildcard src/rng/*.cpp)
INCLUDE=include
INCLUDE_INTERNAL=src/internal
@ -165,5 +165,5 @@ uninstall:
-rmdir $(DESTDIR)$(PREFIX)/include/$(PROJECT)
$(PROJECT)-test: lib$(PROJECT).so
$(CXX) $(CXXFLAGS) src/test/*.cpp -o $@ -l:$< -lfmt -Wl,-flto -Wl,-O3 $(LDFLAGS)
$(CC) $(CFLAGS) src/test/*.c -o $@ -l:$< -lfmt -Wl,-flto -Wl,-O3 $(LDFLAGS)
-valgrind ./$@

@ -73,7 +73,7 @@ typedef __typeof( ((struct rng_next_opt*)NULL)->ty ) rng_next_tyq; // Qualified
// -- C API functions -- (C++ NO compat)
int rng_raw(rng_t* engine, void* restrict output, struct rng_next_opt opt);
void rng_next_bin(rng_t* engine, unsigned char* restrict output, size_t n);
//TODO: Specialised `rng_next` functions
void* rng_next_ty(rng_t* engine, void* restrict output, enum rng_next_type ty, enum rng_next_flag flags);
void* rng_next_tyb(rng_t* engine, void* restrict output, enum rng_next_type ty, enum rng_next_flag flags, const void* pmin, const void* pmax);

@ -8,7 +8,7 @@
#include <rngxx.hpp>
#include <mem.h>
#include <rng/crand.h>
#include <rngxx/crand.h>
#include "crand.h"
// Note: the output of drand48 is uniform between INT32_MIN..=INT32_MAX (inclusive)

@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#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_t* engine = rng_new(RNG_KIND_CRAND, (const u64[]){ 1000 });
printf("%d %d %d\n", next(engine, NULL, TREF(100)), next(engine, TREF(10), TREF(20)), next(engine, NULL, NULL));
rng_free(engine);
return 0;
}
Loading…
Cancel
Save