diff --git a/src/Numerics/Random/RandomSource.cs b/src/Numerics/Random/RandomSource.cs
index fea61287..0eec22e1 100644
--- a/src/Numerics/Random/RandomSource.cs
+++ b/src/Numerics/Random/RandomSource.cs
@@ -469,6 +469,27 @@ namespace MathNet.Numerics.Random
DoSampleBytes(buffer);
}
+
+#if NETCOREAPP2_1_OR_GREATER
+ ///
+ /// Fills the elements of a specified array of bytes with random numbers.
+ ///
+ /// An array of bytes to contain random numbers.
+ public sealed override void NextBytes(Span buffer)
+ {
+ if (_threadSafe)
+ {
+ lock (_lock)
+ {
+ DoSampleBytes(buffer);
+ }
+
+ return;
+ }
+
+ DoSampleBytes(buffer);
+ }
+#endif
///
/// Returns a random number between 0.0 and 1.0.
@@ -511,6 +532,18 @@ namespace MathNet.Numerics.Random
}
}
+#if NETCOREAPP2_1_OR_GREATER
+ ///
+ /// Fills the elements of a specified array of bytes with random numbers in full range, including zero and 255 ().
+ ///
+ protected virtual void DoSampleBytes(Span buffer)
+ {
+ var temp = new byte[buffer.Length];
+ DoSampleBytes(temp);
+ temp.CopyTo(buffer);
+ }
+#endif
+
///
/// 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).