From 7a4f6877c3ea1365a95a490eb2e719ac0ac5d737 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 25 Nov 2025 07:01:28 -0500 Subject: [PATCH] Use Random.GetString in hosting IdGenerator (#2427) --- dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/IdGenerator.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/IdGenerator.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/IdGenerator.cs index bd35fa8308..5741e8d161 100644 --- a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/IdGenerator.cs +++ b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/IdGenerator.cs @@ -146,6 +146,9 @@ internal sealed partial class IdGenerator const string Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; if (random is not null) { +#if NET10_0_OR_GREATER + return random.GetString(Chars, stringLength); +#else // Use deterministic random generation when seed is provided return string.Create(stringLength, random, static (destination, random) => { @@ -154,6 +157,7 @@ internal sealed partial class IdGenerator destination[i] = Chars[random.Next(Chars.Length)]; } }); +#endif } // Use cryptographically secure random generation when no seed is provided