From a5c54ed16c121f8a9803b707f318412881e16bcd Mon Sep 17 00:00:00 2001 From: Infendro Date: Sun, 14 Dec 2025 00:17:29 +0100 Subject: [PATCH] replace IllegalArgumentException with require --- .../kotlin/com/infendro/random/prng/PRNG.kt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/commonMain/kotlin/com/infendro/random/prng/PRNG.kt b/src/commonMain/kotlin/com/infendro/random/prng/PRNG.kt index 52547a7..cc720f0 100644 --- a/src/commonMain/kotlin/com/infendro/random/prng/PRNG.kt +++ b/src/commonMain/kotlin/com/infendro/random/prng/PRNG.kt @@ -15,11 +15,9 @@ abstract class PRNG : Random() { override fun nextBits( bitCount: Int, ): Int { - if (bitCount !in 0..32) - throw IllegalArgumentException() - if (bitCount == 0) - return 0 + require(bitCount in 0..32) + if (bitCount == 0) return 0 return generate(4).toInt() ushr (32 - bitCount) } @@ -28,10 +26,8 @@ abstract class PRNG : Random() { fromIndex: Int, toIndex: Int, ): ByteArray { - if (fromIndex !in 0..array.size || toIndex !in 0..array.size) - throw IllegalArgumentException() - if (fromIndex > toIndex) - throw IllegalArgumentException() + require(fromIndex in 0..array.size && toIndex in 0..array.size) + require(fromIndex <= toIndex) val size = toIndex - fromIndex val bytes = generate(size).asByteArray()