From ac55496d881e0a17b3eff85f1faae5aafbc53b50 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Wed, 22 Jul 2020 17:30:45 +0200 Subject: erster Commit --- random.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 random.h (limited to 'random.h') diff --git a/random.h b/random.h new file mode 100644 index 0000000..9094d5b --- /dev/null +++ b/random.h @@ -0,0 +1,47 @@ +#ifndef ITS1_RANDOM_H_INCLUDED +#define ITS1_RANDOM_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +struct random_ctx { + unsigned char (*get_byte)(struct random_ctx *ctx); +}; + +static unsigned char +random_get_byte(struct random_ctx *ctx) +{ + return ctx->get_byte(ctx); +} + +static unsigned short +random_get_word(struct random_ctx *ctx) +{ + return (ctx->get_byte(ctx) << 8) + | ctx->get_byte(ctx) + ; +} + +static unsigned long +random_get_dword(struct random_ctx *ctx) +{ + return (ctx->get_byte(ctx) << 24) + | (ctx->get_byte(ctx) << 16) + | (ctx->get_byte(ctx) << 8) + | ctx->get_byte(ctx) + ; +} + +static unsigned long +random_get_dword_range(struct random_ctx *ctx, unsigned long l, unsigned long u) +{ + return l + random_get_dword(ctx) % (u - l + 1); +} + +#ifdef __cplusplus +} +#endif + +#endif /* ITS1_RANDOM_H_INCLUDED */ + -- cgit v1.3