Skip to content

.NET: Use Random.GetString in hosting IdGenerator#2427

Merged
stephentoub merged 1 commit into
microsoft:mainfrom
stephentoub:idgen
Nov 25, 2025
Merged

.NET: Use Random.GetString in hosting IdGenerator#2427
stephentoub merged 1 commit into
microsoft:mainfrom
stephentoub:idgen

Conversation

@stephentoub

Copy link
Copy Markdown
Member

No description provided.

@markwallace-microsoft markwallace-microsoft added the .NET Usage: [Issues, PRs], Target: .Net label Nov 24, 2025
@github-actions github-actions Bot changed the title Use Random.GetString in hosting IdGenerator .NET: Use Random.GetString in hosting IdGenerator Nov 24, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes ID generation by using the built-in Random.GetString() method for .NET 10+ instead of manually creating random strings with string.Create(). This simplifies the code and leverages framework optimizations for better performance.

  • Uses conditional compilation to call Random.GetString() when available
  • Maintains backward compatibility with older .NET versions using the existing string.Create() implementation
  • Preserves the deterministic random generation behavior when a seed is provided

Comment thread dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/IdGenerator.cs
@stephentoub stephentoub added this pull request to the merge queue Nov 25, 2025
Merged via the queue into microsoft:main with commit 7a4f687 Nov 25, 2025
21 checks passed
This was referenced Dec 5, 2025
arisng pushed a commit to arisng/agent-framework that referenced this pull request Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants