diff --git a/src/FSharp/Random.fs b/src/FSharp/Random.fs index 7303bc3c..7731f501 100644 --- a/src/FSharp/Random.fs +++ b/src/FSharp/Random.fs @@ -37,9 +37,9 @@ module Random = let shared = SystemRandomSource.Default :> System.Random /// Default sampling, efficient but without custom seed (uses robust seeds internally) - let inline doubles (length:int) = SystemRandomSource.Doubles(length) + let inline doubles (length:int) = SystemRandomSource.FastDoubles(length) let inline doubleSeq () = SystemRandomSource.DoubleSequence() - let inline doubleFill (values:double[]) = SystemRandomSource.Doubles(values) + let inline doubleFill (values:double[]) = SystemRandomSource.FastDoubles(values) let inline doublesSeed (seed:int) (length:int) = SystemRandomSource.Doubles(length, seed) let inline doubleSeqSeed (seed:int) = SystemRandomSource.DoubleSequence(seed) diff --git a/src/Numerics/Generate.cs b/src/Numerics/Generate.cs index 74c552f3..475528d0 100644 --- a/src/Numerics/Generate.cs +++ b/src/Numerics/Generate.cs @@ -546,7 +546,7 @@ namespace MathNet.Numerics /// public static double[] Uniform(int length) { - return SystemRandomSource.Doubles(length); + return SystemRandomSource.FastDoubles(length); } /// @@ -565,7 +565,7 @@ namespace MathNet.Numerics /// public static T[] UniformMap(int length, Func map) { - var samples = SystemRandomSource.Doubles(length); + var samples = SystemRandomSource.FastDoubles(length); var data = new T[length]; for (int i = 0; i < data.Length; i++) { @@ -589,8 +589,8 @@ namespace MathNet.Numerics /// public static T[] UniformMap2(int length, Func map) { - var samples1 = SystemRandomSource.Doubles(length); - var samples2 = SystemRandomSource.Doubles(length); + var samples1 = SystemRandomSource.FastDoubles(length); + var samples2 = SystemRandomSource.FastDoubles(length); var data = new T[length]; for (int i = 0; i < data.Length; i++) { diff --git a/src/Numerics/Random/SystemRandomSource.cs b/src/Numerics/Random/SystemRandomSource.cs index 620868b5..b4967f70 100644 --- a/src/Numerics/Random/SystemRandomSource.cs +++ b/src/Numerics/Random/SystemRandomSource.cs @@ -124,9 +124,10 @@ namespace MathNet.Numerics.Random /// /// Fill an array with uniform random numbers greater than or equal to 0.0 and less than 1.0. + /// WARNING: potentially very short random sequence length, can generate repeated partial sequences. /// /// Parallelized on large length, but also supports being called in parallel from multiple threads - public static void Doubles(double[] values) + public static void FastDoubles(double[] values) { if (values.Length < 2048) { @@ -146,13 +147,14 @@ namespace MathNet.Numerics.Random /// /// Returns an array of uniform random numbers greater than or equal to 0.0 and less than 1.0. + /// WARNING: potentially very short random sequence length, can generate repeated partial sequences. /// /// Parallelized on large length, but also supports being called in parallel from multiple threads [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] - public static double[] Doubles(int length) + public static double[] FastDoubles(int length) { var data = new double[length]; - Doubles(data); + FastDoubles(data); return data; }