diff options
Diffstat (limited to 'random.h')
| -rw-r--r-- | random.h | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/random.h b/random.h deleted file mode 100644 index 9094d5b..0000000 --- a/random.h +++ /dev/null | |||
| @@ -1,47 +0,0 @@ | |||
| 1 | #ifndef ITS1_RANDOM_H_INCLUDED | ||
| 2 | #define ITS1_RANDOM_H_INCLUDED | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | struct random_ctx { | ||
| 9 | unsigned char (*get_byte)(struct random_ctx *ctx); | ||
| 10 | }; | ||
| 11 | |||
| 12 | static unsigned char | ||
| 13 | random_get_byte(struct random_ctx *ctx) | ||
| 14 | { | ||
| 15 | return ctx->get_byte(ctx); | ||
| 16 | } | ||
| 17 | |||
| 18 | static unsigned short | ||
| 19 | random_get_word(struct random_ctx *ctx) | ||
| 20 | { | ||
| 21 | return (ctx->get_byte(ctx) << 8) | ||
| 22 | | ctx->get_byte(ctx) | ||
| 23 | ; | ||
| 24 | } | ||
| 25 | |||
| 26 | static unsigned long | ||
| 27 | random_get_dword(struct random_ctx *ctx) | ||
| 28 | { | ||
| 29 | return (ctx->get_byte(ctx) << 24) | ||
| 30 | | (ctx->get_byte(ctx) << 16) | ||
| 31 | | (ctx->get_byte(ctx) << 8) | ||
| 32 | | ctx->get_byte(ctx) | ||
| 33 | ; | ||
| 34 | } | ||
| 35 | |||
| 36 | static unsigned long | ||
| 37 | random_get_dword_range(struct random_ctx *ctx, unsigned long l, unsigned long u) | ||
| 38 | { | ||
| 39 | return l + random_get_dword(ctx) % (u - l + 1); | ||
| 40 | } | ||
| 41 | |||
| 42 | #ifdef __cplusplus | ||
| 43 | } | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #endif /* ITS1_RANDOM_H_INCLUDED */ | ||
| 47 | |||
