From 37b8f67130bd0240096c75879a4544529d99949b Mon Sep 17 00:00:00 2001 From: Guillermo Santos Date: Sat, 27 Jul 2024 21:14:51 -0400 Subject: [PATCH] Update RandomImpl.cs Implement Random.NextBytes(Span buffer) --- source/Cosmos.System2_Plugs/System/RandomImpl.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/Cosmos.System2_Plugs/System/RandomImpl.cs b/source/Cosmos.System2_Plugs/System/RandomImpl.cs index 368d989531..ae03b89e0d 100644 --- a/source/Cosmos.System2_Plugs/System/RandomImpl.cs +++ b/source/Cosmos.System2_Plugs/System/RandomImpl.cs @@ -172,6 +172,19 @@ public static void NextBytes(Random aThis, byte[] buffer) } } + public static void NextBytes(Random aThis, Span buffer) + { + if (buffer == null) + { + return; + } + + for (int i = 0; i < buffer.Length; i++) + { + buffer[i] = (byte)(InternalSample() % (byte.MaxValue + 1)); + } + } + public static double NextDouble(Random aThis) { return Sample();