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(
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()