Browse Source

Random: make clearer that SystemRandomSource.FastDoubles has low randomness properties

provider
Christoph Ruegg 12 years ago
parent
commit
70f9e982b7
  1. 4
      src/FSharp/Random.fs
  2. 8
      src/Numerics/Generate.cs
  3. 8
      src/Numerics/Random/SystemRandomSource.cs

4
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)

8
src/Numerics/Generate.cs

@ -546,7 +546,7 @@ namespace MathNet.Numerics
/// </summary>
public static double[] Uniform(int length)
{
return SystemRandomSource.Doubles(length);
return SystemRandomSource.FastDoubles(length);
}
/// <summary>
@ -565,7 +565,7 @@ namespace MathNet.Numerics
/// </summary>
public static T[] UniformMap<T>(int length, Func<double, T> 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
/// </summary>
public static T[] UniformMap2<T>(int length, Func<double, double, T> 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++)
{

8
src/Numerics/Random/SystemRandomSource.cs

@ -124,9 +124,10 @@ namespace MathNet.Numerics.Random
/// <summary>
/// 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.
/// </summary>
/// <remarks>Parallelized on large length, but also supports being called in parallel from multiple threads</remarks>
public static void Doubles(double[] values)
public static void FastDoubles(double[] values)
{
if (values.Length < 2048)
{
@ -146,13 +147,14 @@ namespace MathNet.Numerics.Random
/// <summary>
/// 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.
/// </summary>
/// <remarks>Parallelized on large length, but also supports being called in parallel from multiple threads</remarks>
[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;
}

Loading…
Cancel
Save