replace IllegalArgumentException with require
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user