From b36281fa39d810ae1e60d2e7a9e042be754b8687 Mon Sep 17 00:00:00 2001 From: Roland Grinis Date: Wed, 31 Mar 2021 09:23:41 +0100 Subject: [PATCH] roll back --- .../space/kscience/kmath/tensors/core/utils.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/utils.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/utils.kt index e46d39cf2..fc0ebe7fa 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/utils.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/utils.kt @@ -37,10 +37,8 @@ internal fun Buffer.array(): DoubleArray = when (this) { is DoubleBuffer -> array else -> throw RuntimeException("Failed to cast Buffer to DoubleArray") } -/* -internal inline fun getRandomNormals(n: Int,): DoubleArray { - val sampler = BoxMullerNormalizedGaussianSampler.of() - val chain = sampler.sample(RandomGenerator.default) - return (0 until n).map { chain.next() }.toDoubleArray() -} -*/ \ No newline at end of file + +internal inline fun getRandomNormals(n: Int, seed: Long): DoubleArray { + val u = Random(seed) + return (0 until n).map { sqrt(-2.0 * ln(u.nextDouble())) * cos(2.0 * PI * u.nextDouble()) }.toDoubleArray() +} \ No newline at end of file