Add netFloat and nextDouble helper methods to RandomSource

This commit is contained in:
DBotThePony 2025-03-21 13:33:53 +07:00
parent 269227f6cf
commit 9b27ed7fb6
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -662,3 +662,21 @@ fun RandomSource.nextNormalDoubles(stddev: Double, mean: Double): DoublePair {
fun RandomSource.nextNormalDouble(stddev: Double, mean: Double): Double {
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)
}