hikari
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
34 additions and
1 deletions
-
src/Numerics/Numerics.csproj
-
src/Numerics/Random/RandomSource.cs
|
|
|
@ -2,7 +2,7 @@ |
|
|
|
<Project Sdk="Microsoft.NET.Sdk"> |
|
|
|
<PropertyGroup> |
|
|
|
<OutputType>Library</OutputType> |
|
|
|
<TargetFrameworks>net5.0;net461;net48;netstandard2.0</TargetFrameworks> |
|
|
|
<TargetFrameworks>net5.0;netcoreapp2.1;net461;net48;netstandard2.1;netstandard2.0</TargetFrameworks> |
|
|
|
<AssemblyName>MathNet.Numerics</AssemblyName> |
|
|
|
<RootNamespace>MathNet.Numerics</RootNamespace> |
|
|
|
<IsPackable>true</IsPackable> |
|
|
|
|
|
|
|
@ -470,6 +470,27 @@ namespace MathNet.Numerics.Random |
|
|
|
DoSampleBytes(buffer); |
|
|
|
} |
|
|
|
|
|
|
|
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
|
|
|
|
/// <summary>
|
|
|
|
/// Fills the elements of a specified array of bytes with random numbers.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="buffer">An array of bytes to contain random numbers.</param>
|
|
|
|
public sealed override void NextBytes(Span<byte> buffer) |
|
|
|
{ |
|
|
|
if (_threadSafe) |
|
|
|
{ |
|
|
|
lock (_lock) |
|
|
|
{ |
|
|
|
DoSampleBytes(buffer); |
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
DoSampleBytes(buffer); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a random number between 0.0 and 1.0.
|
|
|
|
/// </summary>
|
|
|
|
@ -511,6 +532,18 @@ namespace MathNet.Numerics.Random |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
|
|
|
|
/// <summary>
|
|
|
|
/// Fills the elements of a specified array of bytes with random numbers in full range, including zero and 255 (<see cref="F:System.Byte.MaxValue"/>).
|
|
|
|
/// </summary>
|
|
|
|
protected virtual void DoSampleBytes(Span<byte> buffer) |
|
|
|
{ |
|
|
|
var temp = new byte[buffer.Length]; |
|
|
|
DoSampleBytes(temp); |
|
|
|
temp.CopyTo(buffer); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a random N-bit signed integer greater than or equal to zero and less than 2^N.
|
|
|
|
/// N (bit count) is expected to be greater than zero and less than 32 (not verified).
|
|
|
|
|