Add netFloat and nextDouble helper methods to RandomSource
This commit is contained in:
parent
269227f6cf
commit
9b27ed7fb6
@ -662,3 +662,21 @@ fun RandomSource.nextNormalDoubles(stddev: Double, mean: Double): DoublePair {
|
|||||||
fun RandomSource.nextNormalDouble(stddev: Double, mean: Double): Double {
|
fun RandomSource.nextNormalDouble(stddev: Double, mean: Double): Double {
|
||||||
return nextGaussian() * stddev + mean
|
return nextGaussian() * stddev + mean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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