diff options
| author | Thomas Schmucker <ts@its1.de> | 2022-07-15 08:07:12 +0200 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2022-07-15 08:07:12 +0200 |
| commit | 690fdf2ca329af6c1683507f2f51560d8e00f6c1 (patch) | |
| tree | a25ff97be8d3f0f8630831add02e29960ec9da29 /src/random.h | |
| parent | 07e72af6f78d7316eaed828ac0af6f95ac8e4820 (diff) | |
| parent | 424e1f2a3eb59b97462c5e15ef13b80c66f4ba1b (diff) | |
| download | data-structures-690fdf2ca329af6c1683507f2f51560d8e00f6c1.tar.gz data-structures-690fdf2ca329af6c1683507f2f51560d8e00f6c1.tar.bz2 data-structures-690fdf2ca329af6c1683507f2f51560d8e00f6c1.zip | |
Merge branch 'cleanup'
Diffstat (limited to 'src/random.h')
| -rw-r--r-- | src/random.h | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/src/random.h b/src/random.h deleted file mode 100644 index 9094d5b..0000000 --- a/src/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 | |||
