diff --git a/nanorand-abi/nanorand.h b/nanorand-abi/nanorand.h index e293db5..91e8b5a 100644 --- a/nanorand-abi/nanorand.h +++ b/nanorand-abi/nanorand.h @@ -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 */ @@ -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 */ @@ -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 */ @@ -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 */ @@ -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 */ @@ -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 */ @@ -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); @@ -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 */ @@ -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 */ @@ -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 */ @@ -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 */ diff --git a/nanorand-abi/src/chacha/chacha12.rs b/nanorand-abi/src/chacha/chacha12.rs index 52b9e70..5b51831 100644 --- a/nanorand-abi/src/chacha/chacha12.rs +++ b/nanorand-abi/src/chacha/chacha12.rs @@ -45,6 +45,42 @@ pub extern "C" fn chacha12_next_u64(rng: &mut ChaCha) -> u64 { rng.generate() } +/// Generate a random pointer-sized unsigned integer from the provided ChaCha12 RNG +#[no_mangle] +pub extern "C" fn chacha12_next_usize(rng: &mut ChaCha) -> usize { + rng.generate() +} + +/// Generate a random 8-bit signed integer from the provided ChaCha12 RNG +#[no_mangle] +pub extern "C" fn chacha12_next_i8(rng: &mut ChaCha) -> i8 { + rng.generate() +} + +/// Generate a random 16-bit signed integer from the provided ChaCha12 RNG +#[no_mangle] +pub extern "C" fn chacha12_next_i16(rng: &mut ChaCha) -> i16 { + rng.generate() +} + +/// Generate a random 32-bit signed integer from the provided ChaCha12 RNG +#[no_mangle] +pub extern "C" fn chacha12_next_i32(rng: &mut ChaCha) -> i32 { + rng.generate() +} + +/// Generate a random 64-bit signed integer from the provided ChaCha12 RNG +#[no_mangle] +pub extern "C" fn chacha12_next_i64(rng: &mut ChaCha) -> i64 { + rng.generate() +} + +/// Generate a random pointer-sized signed integer from the provided ChaCha12 RNG +#[no_mangle] +pub extern "C" fn chacha12_next_isize(rng: &mut ChaCha) -> isize { + rng.generate() +} + /// Generate a random boolean value from the provided ChaCha12 RNG #[no_mangle] pub extern "C" fn chacha12_next_bool(rng: &mut ChaCha) -> bool { @@ -80,3 +116,33 @@ pub extern "C" fn chacha12_range_u64(rng: &mut ChaCha, lower: u64, upper: u64) - pub extern "C" fn chacha12_range_usize(rng: &mut ChaCha, lower: usize, upper: usize) -> usize { rng.generate_range(lower..=upper) } + +/// Generate a random 8-bit signed integer within a specified range from the provided ChaCha12 RNG +#[no_mangle] +pub extern "C" fn chacha12_range_i8(rng: &mut ChaCha, lower: i8, upper: i8) -> i8 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 16-bit signed integer within a specified range from the provided ChaCha12 RNG +#[no_mangle] +pub extern "C" fn chacha12_range_i16(rng: &mut ChaCha, lower: i16, upper: i16) -> i16 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 32-bit signed integer within a specified range from the provided ChaCha12 RNG +#[no_mangle] +pub extern "C" fn chacha12_range_i32(rng: &mut ChaCha, lower: i32, upper: i32) -> i32 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 64-bit signed integer within a specified range from the provided ChaCha12 RNG +#[no_mangle] +pub extern "C" fn chacha12_range_i64(rng: &mut ChaCha, lower: i64, upper: i64) -> i64 { + rng.generate_range(lower..=upper) +} + +/// Generate a random pointer-sized signed integer within a specified range from the provided ChaCha12 RNG +#[no_mangle] +pub extern "C" fn chacha12_range_isize(rng: &mut ChaCha, lower: isize, upper: isize) -> isize { + rng.generate_range(lower..=upper) +} diff --git a/nanorand-abi/src/chacha/chacha20.rs b/nanorand-abi/src/chacha/chacha20.rs index c5e36a3..bcb1a11 100644 --- a/nanorand-abi/src/chacha/chacha20.rs +++ b/nanorand-abi/src/chacha/chacha20.rs @@ -45,6 +45,42 @@ pub extern "C" fn chacha20_next_u64(rng: &mut ChaCha) -> u64 { rng.generate() } +/// Generate a random pointer-sized unsigned integer from the provided ChaCha20 RNG +#[no_mangle] +pub extern "C" fn chacha20_next_usize(rng: &mut ChaCha) -> usize { + rng.generate() +} + +/// Generate a random 8-bit signed integer from the provided ChaCha20 RNG +#[no_mangle] +pub extern "C" fn chacha20_next_i8(rng: &mut ChaCha) -> i8 { + rng.generate() +} + +/// Generate a random 16-bit signed integer from the provided ChaCha20 RNG +#[no_mangle] +pub extern "C" fn chacha20_next_i16(rng: &mut ChaCha) -> i16 { + rng.generate() +} + +/// Generate a random 32-bit signed integer from the provided ChaCha20 RNG +#[no_mangle] +pub extern "C" fn chacha20_next_i32(rng: &mut ChaCha) -> i32 { + rng.generate() +} + +/// Generate a random 64-bit signed integer from the provided ChaCha20 RNG +#[no_mangle] +pub extern "C" fn chacha20_next_i64(rng: &mut ChaCha) -> i64 { + rng.generate() +} + +/// Generate a random pointer-sized signed integer from the provided ChaCha20 RNG +#[no_mangle] +pub extern "C" fn chacha20_next_isize(rng: &mut ChaCha) -> isize { + rng.generate() +} + /// Generate a random boolean value from the provided ChaCha20 RNG #[no_mangle] pub extern "C" fn chacha20_next_bool(rng: &mut ChaCha) -> bool { @@ -80,3 +116,33 @@ pub extern "C" fn chacha20_range_u64(rng: &mut ChaCha, lower: u64, upper: u64) - pub extern "C" fn chacha20_range_usize(rng: &mut ChaCha, lower: usize, upper: usize) -> usize { rng.generate_range(lower..=upper) } + +/// Generate a random 8-bit signed integer within a specified range from the provided ChaCha20 RNG +#[no_mangle] +pub extern "C" fn chacha20_range_i8(rng: &mut ChaCha, lower: i8, upper: i8) -> i8 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 16-bit signed integer within a specified range from the provided ChaCha20 RNG +#[no_mangle] +pub extern "C" fn chacha20_range_i16(rng: &mut ChaCha, lower: i16, upper: i16) -> i16 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 32-bit signed integer within a specified range from the provided ChaCha20 RNG +#[no_mangle] +pub extern "C" fn chacha20_range_i32(rng: &mut ChaCha, lower: i32, upper: i32) -> i32 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 64-bit signed integer within a specified range from the provided ChaCha20 RNG +#[no_mangle] +pub extern "C" fn chacha20_range_i64(rng: &mut ChaCha, lower: i64, upper: i64) -> i64 { + rng.generate_range(lower..=upper) +} + +/// Generate a random pointer-sized signed integer within a specified range from the provided ChaCha20 RNG +#[no_mangle] +pub extern "C" fn chacha20_range_isize(rng: &mut ChaCha, lower: isize, upper: isize) -> isize { + rng.generate_range(lower..=upper) +} diff --git a/nanorand-abi/src/chacha/chacha8.rs b/nanorand-abi/src/chacha/chacha8.rs index bf0dd91..2919766 100644 --- a/nanorand-abi/src/chacha/chacha8.rs +++ b/nanorand-abi/src/chacha/chacha8.rs @@ -45,6 +45,42 @@ pub extern "C" fn chacha8_next_u64(rng: &mut ChaCha) -> u64 { rng.generate() } +/// Generate a random pointer-sized unsigned integer from the provided ChaCha8 RNG +#[no_mangle] +pub extern "C" fn chacha8_next_usize(rng: &mut ChaCha) -> usize { + rng.generate() +} + +/// Generate a random 8-bit signed integer from the provided ChaCha8 RNG +#[no_mangle] +pub extern "C" fn chacha8_next_i8(rng: &mut ChaCha) -> i8 { + rng.generate() +} + +/// Generate a random 16-bit signed integer from the provided ChaCha8 RNG +#[no_mangle] +pub extern "C" fn chacha8_next_i16(rng: &mut ChaCha) -> i16 { + rng.generate() +} + +/// Generate a random 32-bit signed integer from the provided ChaCha8 RNG +#[no_mangle] +pub extern "C" fn chacha8_next_i32(rng: &mut ChaCha) -> i32 { + rng.generate() +} + +/// Generate a random 64-bit signed integer from the provided ChaCha8 RNG +#[no_mangle] +pub extern "C" fn chacha8_next_i64(rng: &mut ChaCha) -> i64 { + rng.generate() +} + +/// Generate a random pointer-sized signed integer from the provided ChaCha8 RNG +#[no_mangle] +pub extern "C" fn chacha8_next_isize(rng: &mut ChaCha) -> isize { + rng.generate() +} + /// Generate a random boolean value from the provided ChaCha8 RNG #[no_mangle] pub extern "C" fn chacha8_next_bool(rng: &mut ChaCha) -> bool { @@ -80,3 +116,33 @@ pub extern "C" fn chacha8_range_u64(rng: &mut ChaCha, lower: u64, upper: u64) -> pub extern "C" fn chacha8_range_usize(rng: &mut ChaCha, lower: usize, upper: usize) -> usize { rng.generate_range(lower..=upper) } + +/// Generate a random 8-bit signed integer within a specified range from the provided ChaCha8 RNG +#[no_mangle] +pub extern "C" fn chacha8_range_i8(rng: &mut ChaCha, lower: i8, upper: i8) -> i8 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 16-bit signed integer within a specified range from the provided ChaCha8 RNG +#[no_mangle] +pub extern "C" fn chacha8_range_i16(rng: &mut ChaCha, lower: i16, upper: i16) -> i16 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 32-bit signed integer within a specified range from the provided ChaCha8 RNG +#[no_mangle] +pub extern "C" fn chacha8_range_i32(rng: &mut ChaCha, lower: i32, upper: i32) -> i32 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 64-bit signed integer within a specified range from the provided ChaCha8 RNG +#[no_mangle] +pub extern "C" fn chacha8_range_i64(rng: &mut ChaCha, lower: i64, upper: i64) -> i64 { + rng.generate_range(lower..=upper) +} + +/// Generate a random pointer-sized signed integer within a specified range from the provided ChaCha8 RNG +#[no_mangle] +pub extern "C" fn chacha8_range_isize(rng: &mut ChaCha, lower: isize, upper: isize) -> isize { + rng.generate_range(lower..=upper) +} diff --git a/nanorand-abi/src/pcg64.rs b/nanorand-abi/src/pcg64.rs index 5021ffb..104bae8 100644 --- a/nanorand-abi/src/pcg64.rs +++ b/nanorand-abi/src/pcg64.rs @@ -50,6 +50,36 @@ pub extern "C" fn pcg64_next_usize(rng: &mut Pcg64) -> usize { rng.generate() } +/// Generate a random 8-bit signed integer from the provided RNG +#[no_mangle] +pub extern "C" fn pcg64_next_i8(rng: &mut Pcg64) -> i8 { + rng.generate() +} + +/// Generate a random 16-bit signed integer from the provided RNG +#[no_mangle] +pub extern "C" fn pcg64_next_i16(rng: &mut Pcg64) -> i16 { + rng.generate() +} + +/// Generate a random 32-bit signed integer from the provided RNG +#[no_mangle] +pub extern "C" fn pcg64_next_i32(rng: &mut Pcg64) -> i32 { + rng.generate() +} + +/// Generate a random 64-bit signed integer from the provided RNG +#[no_mangle] +pub extern "C" fn pcg64_next_i64(rng: &mut Pcg64) -> i64 { + rng.generate() +} + +/// Generate a random pointer-sized signed integer from the provided RNG +#[no_mangle] +pub extern "C" fn pcg64_next_isize(rng: &mut Pcg64) -> isize { + rng.generate() +} + /// Generate a random boolean value from the provided RNG #[no_mangle] pub extern "C" fn pcg64_next_bool(rng: &mut Pcg64) -> bool { @@ -85,3 +115,33 @@ pub extern "C" fn pcg64_range_u64(rng: &mut Pcg64, lower: u64, upper: u64) -> u6 pub extern "C" fn pcg64_range_usize(rng: &mut Pcg64, lower: usize, upper: usize) -> usize { rng.generate_range(lower..=upper) } + +/// Generate a random 8-bit signed integer within a specified range from the provided RNG +#[no_mangle] +pub extern "C" fn pcg64_range_i8(rng: &mut Pcg64, lower: i8, upper: i8) -> i8 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 16-bit signed integer within a specified range from the provided RNG +#[no_mangle] +pub extern "C" fn pcg64_range_i16(rng: &mut Pcg64, lower: i16, upper: i16) -> i16 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 32-bit signed integer within a specified range from the provided RNG +#[no_mangle] +pub extern "C" fn pcg64_range_i32(rng: &mut Pcg64, lower: i32, upper: i32) -> i32 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 64-bit signed integer within a specified range from the provided RNG +#[no_mangle] +pub extern "C" fn pcg64_range_i64(rng: &mut Pcg64, lower: i64, upper: i64) -> i64 { + rng.generate_range(lower..=upper) +} + +/// Generate a random pointer-sized signed integer within a specified range from the provided RNG +#[no_mangle] +pub extern "C" fn pcg64_range_isize(rng: &mut Pcg64, lower: isize, upper: isize) -> isize { + rng.generate_range(lower..=upper) +} diff --git a/nanorand-abi/src/wyrand.rs b/nanorand-abi/src/wyrand.rs index c7b8439..da77923 100644 --- a/nanorand-abi/src/wyrand.rs +++ b/nanorand-abi/src/wyrand.rs @@ -1,12 +1,12 @@ use nanorand::{Rng, WyRand}; -/// Create a new Pcg64 RNG, using system-provided entropy. +/// Create a new WyRand RNG, using system-provided entropy. #[no_mangle] pub extern "C" fn new_wyrand() -> WyRand { WyRand::new() } -/// Create a new Pcg64 RNG, using a given seed. +/// Create a new WyRand RNG, using a given seed. #[no_mangle] pub extern "C" fn new_wyrand_with_seed(seed: u64) -> WyRand { WyRand::new_seed(seed) @@ -50,6 +50,36 @@ pub extern "C" fn wyrand_next_usize(rng: &mut WyRand) -> usize { rng.generate() } +/// Generate a random 8-bit signed integer from the provided RNG +#[no_mangle] +pub extern "C" fn wyrand_next_i8(rng: &mut WyRand) -> i8 { + rng.generate() +} + +/// Generate a random 16-bit signed integer from the provided RNG +#[no_mangle] +pub extern "C" fn wyrand_next_i16(rng: &mut WyRand) -> i16 { + rng.generate() +} + +/// Generate a random 32-bit signed integer from the provided RNG +#[no_mangle] +pub extern "C" fn wyrand_next_i32(rng: &mut WyRand) -> i32 { + rng.generate() +} + +/// Generate a random 64-bit signed integer from the provided RNG +#[no_mangle] +pub extern "C" fn wyrand_next_i64(rng: &mut WyRand) -> i64 { + rng.generate() +} + +/// Generate a random pointer-sized signed integer from the provided RNG +#[no_mangle] +pub extern "C" fn wyrand_next_isize(rng: &mut WyRand) -> isize { + rng.generate() +} + /// Generate a random boolean value from the provided RNG #[no_mangle] pub extern "C" fn wyrand_next_bool(rng: &mut WyRand) -> bool { @@ -85,3 +115,33 @@ pub extern "C" fn wyrand_range_u64(rng: &mut WyRand, lower: u64, upper: u64) -> pub extern "C" fn wyrand_range_usize(rng: &mut WyRand, lower: usize, upper: usize) -> usize { rng.generate_range(lower..=upper) } + +/// Generate a random 8-bit signed integer within a specified range from the provided RNG +#[no_mangle] +pub extern "C" fn wyrand_range_i8(rng: &mut WyRand, lower: i8, upper: i8) -> i8 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 16-bit signed integer within a specified range from the provided RNG +#[no_mangle] +pub extern "C" fn wyrand_range_i16(rng: &mut WyRand, lower: i16, upper: i16) -> i16 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 32-bit signed integer within a specified range from the provided RNG +#[no_mangle] +pub extern "C" fn wyrand_range_i32(rng: &mut WyRand, lower: i32, upper: i32) -> i32 { + rng.generate_range(lower..=upper) +} + +/// Generate a random 64-bit signed integer within a specified range from the provided RNG +#[no_mangle] +pub extern "C" fn wyrand_range_i64(rng: &mut WyRand, lower: i64, upper: i64) -> i64 { + rng.generate_range(lower..=upper) +} + +/// Generate a random pointer-sized signed integer within a specified range from the provided RNG +#[no_mangle] +pub extern "C" fn wyrand_range_isize(rng: &mut WyRand, lower: isize, upper: isize) -> isize { + rng.generate_range(lower..=upper) +} diff --git a/nanorand-py/src/chacha.rs b/nanorand-py/src/chacha.rs index c7ccc70..ae616c6 100644 --- a/nanorand-py/src/chacha.rs +++ b/nanorand-py/src/chacha.rs @@ -25,49 +25,115 @@ macro_rules! chacha_impl { } } + // Get the raw output of the provided RNG pub fn next_bytes(&mut self) -> Vec { self.inner.rand().to_vec() } + /// Generate a random 8-bit unsigned integer from the provided RNG pub fn next_u8(&mut self) -> u8 { self.inner.generate() } + /// Generate a random 16-bit unsigned integer from the provided RNG pub fn next_u16(&mut self) -> u16 { self.inner.generate() } + /// Generate a random 32-bit unsigned integer from the provided RNG pub fn next_u32(&mut self) -> u32 { self.inner.generate() } + /// Generate a random 64-bit unsigned integer from the provided RNG pub fn next_u64(&mut self) -> u64 { self.inner.generate() } + /// Generate a random pointer-sized unsigned integer from the provided RNG pub fn next_usize(&mut self) -> usize { self.inner.generate() } + /// Generate a random 8-bit signed integer from the provided RNG + pub fn next_i8(&mut self) -> i8 { + self.inner.generate() + } + + /// Generate a random 16-bit signed integer from the provided RNG + pub fn next_i16(&mut self) -> i16 { + self.inner.generate() + } + + /// Generate a random 32-bit signed integer from the provided RNG + pub fn next_i32(&mut self) -> i32 { + self.inner.generate() + } + + /// Generate a random 64-bit signed integer from the provided RNG + pub fn next_i64(&mut self) -> i64 { + self.inner.generate() + } + + /// Generate a random pointer-sized signed integer from the provided RNG + pub fn next_isize(&mut self) -> isize { + self.inner.generate() + } + + /// Generate a random boolean from the provided RNG pub fn next_bool(&mut self) -> bool { self.inner.generate() } + /// Generate a random 8-bit unsigned integer within a specified range from the provided RNG pub fn range_u8(&mut self, lower: u8, upper: u8) -> u8 { self.inner.generate_range(lower..=upper) } + /// Generate a random 16-bit unsigned integer within a specified range from the provided RNG pub fn range_u16(&mut self, lower: u16, upper: u16) -> u16 { self.inner.generate_range(lower..=upper) } + /// Generate a random 32-bit unsigned integer within a specified range from the provided RNG pub fn range_u32(&mut self, lower: u32, upper: u32) -> u32 { self.inner.generate_range(lower..=upper) } + /// Generate a random 64-bit unsigned integer within a specified range from the provided RNG pub fn range_u64(&mut self, lower: u64, upper: u64) -> u64 { self.inner.generate_range(lower..=upper) } + + /// Generate a random pointer-sized unsigned integer within a specified range from the provided RNG + pub fn range_usize(&mut self, lower: usize, upper: usize) -> usize { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random 8-bit signed integer within a specified range from the provided RNG + pub fn range_i8(&mut self, lower: i8, upper: i8) -> i8 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random 16-bit signed integer within a specified range from the provided RNG + pub fn range_i16(&mut self, lower: i16, upper: i16) -> i16 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random 32-bit signed integer within a specified range from the provided RNG + pub fn range_i32(&mut self, lower: i32, upper: i32) -> i32 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random 64-bit signed integer within a specified range from the provided RNG + pub fn range_i64(&mut self, lower: i64, upper: i64) -> i64 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random pointer-sized signed integer within a specified range from the provided RNG + pub fn range_isize(&mut self, lower: isize, upper: isize) -> isize { + self.inner.generate_range(lower..=upper) + } } }; } diff --git a/nanorand-py/src/pcg64.rs b/nanorand-py/src/pcg64.rs index cbf28d4..42fbaf9 100644 --- a/nanorand-py/src/pcg64.rs +++ b/nanorand-py/src/pcg64.rs @@ -23,43 +23,113 @@ impl Pcg64 { } } + // Get the raw output of the provided RNG pub fn next_bytes(&mut self) -> Vec { self.inner.rand().to_vec() } + /// Generate a random 8-bit unsigned integer from the provided RNG pub fn next_u8(&mut self) -> u8 { self.inner.generate() } + /// Generate a random 16-bit unsigned integer from the provided RNG pub fn next_u16(&mut self) -> u16 { self.inner.generate() } + /// Generate a random 32-bit unsigned integer from the provided RNG pub fn next_u32(&mut self) -> u32 { self.inner.generate() } + /// Generate a random 64-bit unsigned integer from the provided RNG pub fn next_u64(&mut self) -> u64 { self.inner.generate() } + /// Generate a random pointer-sized unsigned integer from the provided RNG + pub fn next_usize(&mut self) -> usize { + self.inner.generate() + } + + /// Generate a random 8-bit signed integer from the provided RNG + pub fn next_i8(&mut self) -> i8 { + self.inner.generate() + } + + /// Generate a random 16-bit signed integer from the provided RNG + pub fn next_i16(&mut self) -> i16 { + self.inner.generate() + } + + /// Generate a random 32-bit signed integer from the provided RNG + pub fn next_i32(&mut self) -> i32 { + self.inner.generate() + } + + /// Generate a random 64-bit signed integer from the provided RNG + pub fn next_i64(&mut self) -> i64 { + self.inner.generate() + } + + /// Generate a random pointer-sized signed integer from the provided RNG + pub fn next_isize(&mut self) -> isize { + self.inner.generate() + } + + /// Generate a random boolean from the provided RNG pub fn next_bool(&mut self) -> bool { self.inner.generate() } + /// Generate a random 8-bit unsigned integer within a specified range from the provided RNG pub fn range_u8(&mut self, lower: u8, upper: u8) -> u8 { self.inner.generate_range(lower..=upper) } + /// Generate a random 16-bit unsigned integer within a specified range from the provided RNG pub fn range_u16(&mut self, lower: u16, upper: u16) -> u16 { self.inner.generate_range(lower..=upper) } + /// Generate a random 32-bit unsigned integer within a specified range from the provided RNG pub fn range_u32(&mut self, lower: u32, upper: u32) -> u32 { self.inner.generate_range(lower..=upper) } + /// Generate a random 64-bit unsigned integer within a specified range from the provided RNG pub fn range_u64(&mut self, lower: u64, upper: u64) -> u64 { self.inner.generate_range(lower..=upper) } + + /// Generate a random pointer-sized unsigned integer within a specified range from the provided RNG + pub fn range_usize(&mut self, lower: usize, upper: usize) -> usize { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random 8-bit signed integer within a specified range from the provided RNG + pub fn range_i8(&mut self, lower: i8, upper: i8) -> i8 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random 16-bit signed integer within a specified range from the provided RNG + pub fn range_i16(&mut self, lower: i16, upper: i16) -> i16 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random 32-bit signed integer within a specified range from the provided RNG + pub fn range_i32(&mut self, lower: i32, upper: i32) -> i32 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random 64-bit signed integer within a specified range from the provided RNG + pub fn range_i64(&mut self, lower: i64, upper: i64) -> i64 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random pointer-sized signed integer within a specified range from the provided RNG + pub fn range_isize(&mut self, lower: isize, upper: isize) -> isize { + self.inner.generate_range(lower..=upper) + } } diff --git a/nanorand-py/src/wyrand.rs b/nanorand-py/src/wyrand.rs index e95c09f..c97dc87 100644 --- a/nanorand-py/src/wyrand.rs +++ b/nanorand-py/src/wyrand.rs @@ -23,6 +23,7 @@ impl WyRand { } } + // Get the raw output of the provided RNG pub fn next_bytes(&mut self) -> Vec { self.inner.rand().to_vec() } @@ -47,7 +48,37 @@ impl WyRand { self.inner.generate() } - /// Generate a random boolean value from the provided RNG + /// Generate a random pointer-sized unsigned integer from the provided RNG + pub fn next_usize(&mut self) -> usize { + self.inner.generate() + } + + /// Generate a random 8-bit signed integer from the provided RNG + pub fn next_i8(&mut self) -> i8 { + self.inner.generate() + } + + /// Generate a random 16-bit signed integer from the provided RNG + pub fn next_i16(&mut self) -> i16 { + self.inner.generate() + } + + /// Generate a random 32-bit signed integer from the provided RNG + pub fn next_i32(&mut self) -> i32 { + self.inner.generate() + } + + /// Generate a random 64-bit signed integer from the provided RNG + pub fn next_i64(&mut self) -> i64 { + self.inner.generate() + } + + /// Generate a random pointer-sized signed integer from the provided RNG + pub fn next_isize(&mut self) -> isize { + self.inner.generate() + } + + /// Generate a random boolean from the provided RNG pub fn next_bool(&mut self) -> bool { self.inner.generate() } @@ -76,4 +107,29 @@ impl WyRand { pub fn range_usize(&mut self, lower: usize, upper: usize) -> usize { self.inner.generate_range(lower..=upper) } + + /// Generate a random 8-bit signed integer within a specified range from the provided RNG + pub fn range_i8(&mut self, lower: i8, upper: i8) -> i8 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random 16-bit signed integer within a specified range from the provided RNG + pub fn range_i16(&mut self, lower: i16, upper: i16) -> i16 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random 32-bit signed integer within a specified range from the provided RNG + pub fn range_i32(&mut self, lower: i32, upper: i32) -> i32 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random 64-bit signed integer within a specified range from the provided RNG + pub fn range_i64(&mut self, lower: i64, upper: i64) -> i64 { + self.inner.generate_range(lower..=upper) + } + + /// Generate a random pointer-sized signed integer within a specified range from the provided RNG + pub fn range_isize(&mut self, lower: isize, upper: isize) -> isize { + self.inner.generate_range(lower..=upper) + } }