#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 */

