replace IllegalArgumentException with require

This commit is contained in:
2025-12-14 00:17:29 +01:00
parent f3a2e18d2e
commit a5c54ed16c

View File

@@ -15,11 +15,9 @@ abstract class PRNG : Random() {
override fun nextBits( override fun nextBits(
bitCount: Int, bitCount: Int,
): Int { ): Int {
if (bitCount !in 0..32) require(bitCount in 0..32)
throw IllegalArgumentException()
if (bitCount == 0)
return 0
if (bitCount == 0) return 0
return generate(4).toInt() ushr (32 - bitCount) return generate(4).toInt() ushr (32 - bitCount)
} }
@@ -28,10 +26,8 @@ abstract class PRNG : Random() {
fromIndex: Int, fromIndex: Int,
toIndex: Int, toIndex: Int,
): ByteArray { ): ByteArray {
if (fromIndex !in 0..array.size || toIndex !in 0..array.size) require(fromIndex in 0..array.size && toIndex in 0..array.size)
throw IllegalArgumentException() require(fromIndex <= toIndex)
if (fromIndex > toIndex)
throw IllegalArgumentException()
val size = toIndex - fromIndex val size = toIndex - fromIndex
val bytes = generate(size).asByteArray() val bytes = generate(size).asByteArray()