Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[orx-noise] use common gaussian method #170

Merged
merged 1 commit into from
Feb 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions orx-noise/src/main/kotlin/Random.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,7 @@ object Random {
}

fun gaussian(mean: Double = 0.0, standardDeviation: Double = 1.0): Double {
if (hasNextGaussian) {
val result = nextGaussian
nextGaussian = 0.0
hasNextGaussian = false

return mean + standardDeviation * result
} else {
var v1 = 0.0
var v2 = 0.0
var s = 0.0

while (s >= 1.0 || s == 0.0) {
v1 = double() // between -1 and 1
v2 = double() // between -1 and 1
s = v1 * v1 + v2 * v2
}
val multiplier = sqrt(-2.0 * ln(s) / s)

nextGaussian = (v2 * multiplier)
hasNextGaussian = true
return mean + standardDeviation * (v1 * multiplier)
}
return gaussian(mean, standardDeviation, rnd)
}

/**
Expand Down