From 70e87c73ce87d5fb2cd60f9b640ee2e4ec0f2685 Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Thu, 20 Feb 2025 16:56:15 +0100 Subject: [PATCH] [orx-noise] Add Double.uniforms() --- .../src/commonMain/kotlin/UniformRandom.kt | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/orx-noise/src/commonMain/kotlin/UniformRandom.kt b/orx-noise/src/commonMain/kotlin/UniformRandom.kt index e19224b9..920061a3 100644 --- a/orx-noise/src/commonMain/kotlin/UniformRandom.kt +++ b/orx-noise/src/commonMain/kotlin/UniformRandom.kt @@ -39,6 +39,25 @@ fun Double.Companion.uniform( ) = (random.nextDouble() * (max - min)) + min + +/** + * Generates a list of random double values within the specified range. + * + * @param count The number of random double values to generate. + * @param min The minimum value (inclusive) of the range. Default is -1.0. + * @param max The maximum value (exclusive) of the range. Default is 1.0. + * @param random The random number generator to use. Default is Random.Default. + * @return A list of random double values within the specified range. + */ +fun Double.Companion.uniforms( + count: Int, + min: Double = -1.0, max: Double = 1.0, + random: Random = Random.Default +) = + List(count) { + (random.nextDouble() * (max - min)) + min + } + fun Double.Companion.hash( seed: Int, x: Int, min: Double = -1.0, max: Double = 1.0 @@ -396,7 +415,11 @@ fun Vector4.Companion.uniform(min: Double = -1.0, max: Double = 1.0, random: Ran * @param random The random number generator to use. Defaults to Random.Default. * @return A 4-dimensional vector with components uniformly distributed between the specified minimum and maximum values. */ -fun Vector4.Companion.uniform(min: Vector4 = -ONE, max: Vector4 = ONE, random: Random = Random.Default): Vector4 { +fun Vector4.Companion.uniform( + min: Vector4 = -ONE, + max: Vector4 = ONE, + random: Random = Random.Default +): Vector4 { return Vector4( Double.uniform(min.x, max.x, random), Double.uniform(min.y, max.y, random),