Use RandomGenerator methods when available
This commit is contained in:
parent
e1d3b36dab
commit
19e405d4f4
@ -660,12 +660,18 @@ fun RandomSource.nextNormalDouble(stddev: Double, mean: Double): Double {
|
||||
}
|
||||
|
||||
fun RandomSource.nextFloat(min: Float, max: Float): Float {
|
||||
if (this is RandomGenerator)
|
||||
return nextFloat(min, max)
|
||||
|
||||
require(max >= min) { "Min is bigger than max: $min vs $max" }
|
||||
if (min == max) return min
|
||||
return min + nextFloat() * (max - min)
|
||||
}
|
||||
|
||||
fun RandomSource.nextDouble(min: Double, max: Double): Double {
|
||||
if (this is RandomGenerator)
|
||||
return nextDouble(min, max)
|
||||
|
||||
require(max >= min) { "Min is bigger than max: $min vs $max" }
|
||||
if (min == max) return min
|
||||
return min + nextDouble() * (max - min)
|
||||
|
Loading…
Reference in New Issue
Block a user