Skip to content

Commit

Permalink
feat: add support for signed integers to nanorand-abi and `nanorand…
Browse files Browse the repository at this point in the history
…-py`
  • Loading branch information
Absolucy committed Jul 8, 2021
1 parent 3dbae46 commit 8e282f2
Show file tree
Hide file tree
Showing 9 changed files with 786 additions and 5 deletions.
275 changes: 273 additions & 2 deletions nanorand-abi/nanorand.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,31 @@ uint8_t *chacha12_next(ChaCha *rng);
*/
bool chacha12_next_bool(ChaCha *rng);

/**
* Generate a random 16-bit signed integer from the provided ChaCha12 RNG
*/
int16_t chacha12_next_i16(ChaCha *rng);

/**
* Generate a random 32-bit signed integer from the provided ChaCha12 RNG
*/
int32_t chacha12_next_i32(ChaCha *rng);

/**
* Generate a random 64-bit signed integer from the provided ChaCha12 RNG
*/
int64_t chacha12_next_i64(ChaCha *rng);

/**
* Generate a random 8-bit signed integer from the provided ChaCha12 RNG
*/
int8_t chacha12_next_i8(ChaCha *rng);

/**
* Generate a random pointer-sized signed integer from the provided ChaCha12 RNG
*/
intptr_t chacha12_next_isize(ChaCha *rng);

/**
* Generate a random 16-bit unsigned integer from the provided ChaCha12 RNG
*/
Expand All @@ -89,6 +114,38 @@ uint64_t chacha12_next_u64(ChaCha *rng);
*/
uint8_t chacha12_next_u8(ChaCha *rng);

/**
* Generate a random pointer-sized unsigned integer from the provided ChaCha12 RNG
*/
uintptr_t chacha12_next_usize(ChaCha *rng);

/**
* Generate a random 16-bit signed integer within a specified range from the provided ChaCha12 RNG
*/
int16_t chacha12_range_i16(ChaCha *rng, int16_t lower, int16_t upper);

/**
* Generate a random 32-bit signed integer within a specified range from the provided ChaCha12 RNG
*/
int32_t chacha12_range_i32(ChaCha *rng, int32_t lower, int32_t upper);

/**
* Generate a random 64-bit signed integer within a specified range from the provided ChaCha12 RNG
*/
int64_t chacha12_range_i64(ChaCha *rng, int64_t lower, int64_t upper);

/**
* Generate a random 8-bit signed integer within a specified range from the provided ChaCha12 RNG
*/
int8_t chacha12_range_i8(ChaCha *rng, int8_t lower, int8_t upper);

/**
* Generate a random pointer-sized signed integer within a specified range from the provided ChaCha12 RNG
*/
intptr_t chacha12_range_isize(ChaCha *rng,
intptr_t lower,
intptr_t upper);

/**
* Generate a random 16-bit unsigned integer within a specified range from the provided ChaCha12 RNG
*/
Expand Down Expand Up @@ -127,6 +184,31 @@ uint8_t *chacha20_next(ChaCha *rng);
*/
bool chacha20_next_bool(ChaCha *rng);

/**
* Generate a random 16-bit signed integer from the provided ChaCha20 RNG
*/
int16_t chacha20_next_i16(ChaCha *rng);

/**
* Generate a random 32-bit signed integer from the provided ChaCha20 RNG
*/
int32_t chacha20_next_i32(ChaCha *rng);

/**
* Generate a random 64-bit signed integer from the provided ChaCha20 RNG
*/
int64_t chacha20_next_i64(ChaCha *rng);

/**
* Generate a random 8-bit signed integer from the provided ChaCha20 RNG
*/
int8_t chacha20_next_i8(ChaCha *rng);

/**
* Generate a random pointer-sized signed integer from the provided ChaCha20 RNG
*/
intptr_t chacha20_next_isize(ChaCha *rng);

/**
* Generate a random 16-bit unsigned integer from the provided ChaCha20 RNG
*/
Expand All @@ -147,6 +229,38 @@ uint64_t chacha20_next_u64(ChaCha *rng);
*/
uint8_t chacha20_next_u8(ChaCha *rng);

/**
* Generate a random pointer-sized unsigned integer from the provided ChaCha20 RNG
*/
uintptr_t chacha20_next_usize(ChaCha *rng);

/**
* Generate a random 16-bit signed integer within a specified range from the provided ChaCha20 RNG
*/
int16_t chacha20_range_i16(ChaCha *rng, int16_t lower, int16_t upper);

/**
* Generate a random 32-bit signed integer within a specified range from the provided ChaCha20 RNG
*/
int32_t chacha20_range_i32(ChaCha *rng, int32_t lower, int32_t upper);

/**
* Generate a random 64-bit signed integer within a specified range from the provided ChaCha20 RNG
*/
int64_t chacha20_range_i64(ChaCha *rng, int64_t lower, int64_t upper);

/**
* Generate a random 8-bit signed integer within a specified range from the provided ChaCha20 RNG
*/
int8_t chacha20_range_i8(ChaCha *rng, int8_t lower, int8_t upper);

/**
* Generate a random pointer-sized signed integer within a specified range from the provided ChaCha20 RNG
*/
intptr_t chacha20_range_isize(ChaCha *rng,
intptr_t lower,
intptr_t upper);

/**
* Generate a random 16-bit unsigned integer within a specified range from the provided ChaCha20 RNG
*/
Expand Down Expand Up @@ -185,6 +299,31 @@ uint8_t *chacha8_next(ChaCha *rng);
*/
bool chacha8_next_bool(ChaCha *rng);

/**
* Generate a random 16-bit signed integer from the provided ChaCha8 RNG
*/
int16_t chacha8_next_i16(ChaCha *rng);

/**
* Generate a random 32-bit signed integer from the provided ChaCha8 RNG
*/
int32_t chacha8_next_i32(ChaCha *rng);

/**
* Generate a random 64-bit signed integer from the provided ChaCha8 RNG
*/
int64_t chacha8_next_i64(ChaCha *rng);

/**
* Generate a random 8-bit signed integer from the provided ChaCha8 RNG
*/
int8_t chacha8_next_i8(ChaCha *rng);

/**
* Generate a random pointer-sized signed integer from the provided ChaCha8 RNG
*/
intptr_t chacha8_next_isize(ChaCha *rng);

/**
* Generate a random 16-bit unsigned integer from the provided ChaCha8 RNG
*/
Expand All @@ -205,6 +344,38 @@ uint64_t chacha8_next_u64(ChaCha *rng);
*/
uint8_t chacha8_next_u8(ChaCha *rng);

/**
* Generate a random pointer-sized unsigned integer from the provided ChaCha8 RNG
*/
uintptr_t chacha8_next_usize(ChaCha *rng);

/**
* Generate a random 16-bit signed integer within a specified range from the provided ChaCha8 RNG
*/
int16_t chacha8_range_i16(ChaCha *rng, int16_t lower, int16_t upper);

/**
* Generate a random 32-bit signed integer within a specified range from the provided ChaCha8 RNG
*/
int32_t chacha8_range_i32(ChaCha *rng, int32_t lower, int32_t upper);

/**
* Generate a random 64-bit signed integer within a specified range from the provided ChaCha8 RNG
*/
int64_t chacha8_range_i64(ChaCha *rng, int64_t lower, int64_t upper);

/**
* Generate a random 8-bit signed integer within a specified range from the provided ChaCha8 RNG
*/
int8_t chacha8_range_i8(ChaCha *rng, int8_t lower, int8_t upper);

/**
* Generate a random pointer-sized signed integer within a specified range from the provided ChaCha8 RNG
*/
intptr_t chacha8_range_isize(ChaCha *rng,
intptr_t lower,
intptr_t upper);

/**
* Generate a random 16-bit unsigned integer within a specified range from the provided ChaCha8 RNG
*/
Expand Down Expand Up @@ -253,12 +424,12 @@ ChaCha new_chacha8();
Pcg64 new_pcg64();

/**
* Create a new Pcg64 RNG, using system-provided entropy.
* Create a new WyRand RNG, using system-provided entropy.
*/
WyRand new_wyrand();

/**
* Create a new Pcg64 RNG, using a given seed.
* Create a new WyRand RNG, using a given seed.
*/
WyRand new_wyrand_with_seed(uint64_t seed);

Expand All @@ -273,6 +444,31 @@ uint8_t *pcg64_next(Pcg64 *rng);
*/
bool pcg64_next_bool(Pcg64 *rng);

/**
* Generate a random 16-bit signed integer from the provided RNG
*/
int16_t pcg64_next_i16(Pcg64 *rng);

/**
* Generate a random 32-bit signed integer from the provided RNG
*/
int32_t pcg64_next_i32(Pcg64 *rng);

/**
* Generate a random 64-bit signed integer from the provided RNG
*/
int64_t pcg64_next_i64(Pcg64 *rng);

/**
* Generate a random 8-bit signed integer from the provided RNG
*/
int8_t pcg64_next_i8(Pcg64 *rng);

/**
* Generate a random pointer-sized signed integer from the provided RNG
*/
intptr_t pcg64_next_isize(Pcg64 *rng);

/**
* Generate a random 16-bit unsigned integer from the provided RNG
*/
Expand All @@ -298,6 +494,31 @@ uint8_t pcg64_next_u8(Pcg64 *rng);
*/
uintptr_t pcg64_next_usize(Pcg64 *rng);

/**
* Generate a random 16-bit signed integer within a specified range from the provided RNG
*/
int16_t pcg64_range_i16(Pcg64 *rng, int16_t lower, int16_t upper);

/**
* Generate a random 32-bit signed integer within a specified range from the provided RNG
*/
int32_t pcg64_range_i32(Pcg64 *rng, int32_t lower, int32_t upper);

/**
* Generate a random 64-bit signed integer within a specified range from the provided RNG
*/
int64_t pcg64_range_i64(Pcg64 *rng, int64_t lower, int64_t upper);

/**
* Generate a random 8-bit signed integer within a specified range from the provided RNG
*/
int8_t pcg64_range_i8(Pcg64 *rng, int8_t lower, int8_t upper);

/**
* Generate a random pointer-sized signed integer within a specified range from the provided RNG
*/
intptr_t pcg64_range_isize(Pcg64 *rng, intptr_t lower, intptr_t upper);

/**
* Generate a random 16-bit unsigned integer within a specified range from the provided RNG
*/
Expand Down Expand Up @@ -334,6 +555,31 @@ uint8_t *wyrand_next(WyRand *rng);
*/
bool wyrand_next_bool(WyRand *rng);

/**
* Generate a random 16-bit signed integer from the provided RNG
*/
int16_t wyrand_next_i16(WyRand *rng);

/**
* Generate a random 32-bit signed integer from the provided RNG
*/
int32_t wyrand_next_i32(WyRand *rng);

/**
* Generate a random 64-bit signed integer from the provided RNG
*/
int64_t wyrand_next_i64(WyRand *rng);

/**
* Generate a random 8-bit signed integer from the provided RNG
*/
int8_t wyrand_next_i8(WyRand *rng);

/**
* Generate a random pointer-sized signed integer from the provided RNG
*/
intptr_t wyrand_next_isize(WyRand *rng);

/**
* Generate a random 16-bit unsigned integer from the provided RNG
*/
Expand All @@ -359,6 +605,31 @@ uint8_t wyrand_next_u8(WyRand *rng);
*/
uintptr_t wyrand_next_usize(WyRand *rng);

/**
* Generate a random 16-bit signed integer within a specified range from the provided RNG
*/
int16_t wyrand_range_i16(WyRand *rng, int16_t lower, int16_t upper);

/**
* Generate a random 32-bit signed integer within a specified range from the provided RNG
*/
int32_t wyrand_range_i32(WyRand *rng, int32_t lower, int32_t upper);

/**
* Generate a random 64-bit signed integer within a specified range from the provided RNG
*/
int64_t wyrand_range_i64(WyRand *rng, int64_t lower, int64_t upper);

/**
* Generate a random 8-bit signed integer within a specified range from the provided RNG
*/
int8_t wyrand_range_i8(WyRand *rng, int8_t lower, int8_t upper);

/**
* Generate a random pointer-sized signed integer within a specified range from the provided RNG
*/
intptr_t wyrand_range_isize(WyRand *rng, intptr_t lower, intptr_t upper);

/**
* Generate a random 16-bit unsigned integer within a specified range from the provided RNG
*/
Expand Down
Loading

0 comments on commit 8e282f2

Please sign in to comment.