// C api for rngxx #ifndef _RNGXX_H #define _RNGXX_H #ifndef _RNGXX_IMPL #define _RNGXX_COMMON_MINIMAL #endif #include "rngxx/internal/common.h" #ifndef _RNGXX_IMPL #undef _RNGXX_COMMON_MINIMAL #endif #ifdef __cplusplus #ifndef _RNGXX_IMPL_ONLY_TYPES #warning "C++ compilers might not like this header file. Please use the C++ interface for C++ TUs" #endif extern "C" { #endif // -- C API types -- (C++ compat) typedef struct Random rng_t; enum rng_kind { RNG_KIND_CRAND, }; enum rng_next_flag { RNG_TYQ_SIGNED = 0, // Binary with `unsigned`. RNG_TYQ_UNSIGNED = 1 << 0, RNG_TYQ_CHAOS = 1 << 1, }; // 2 bits typedef int rng_bool_t; enum rng_next_type { RNG_TY_BLOB = 0, RNG_TY_BOOL, // Expects type `rng_bool_t`. RNG_TY_INT8, RNG_TY_INT16, RNG_TY_INT32, RNG_TY_INT64, RNG_TY_F32, RNG_TY_F64, }; // 4 bits struct rng_next_opt { union { // Bounded types struct { const void* restrict pmin; const void* restrict pmax; } range; // Blob types size_t len; } bound; struct { enum rng_next_type type : 4; enum rng_next_flag mod : 2; uint8_t _unused : 2; } ty; // 8 bits }; typedef __typeof( ((struct rng_next_opt*)NULL)->ty ) rng_next_tyq; // Qualified type // -- // -- #ifndef _RNGXX_IMPL_ONLY_TYPES // -- 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); 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); rng_t* rng_new(enum rng_kind kind, const u64 seed[static restrict 1]); void rng_free(rng_t* rng); // -- // -- #endif #ifdef __cplusplus } #endif #endif /* _RNGXX_H */