© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•13mo ago•
22 replies
AsyncAndy

Enumerable.OrderBy help

I'm following a tutorial and they randomly get an element of an enumerable like this:

return unvisitedCells.OrderBy(_ => Random.Range(0, 10)).FirstOrDefault();
return unvisitedCells.OrderBy(_ => Random.Range(0, 10)).FirstOrDefault();


I'm a bit confused as to how this works. I looked up the docs for .OrderBy and kind of understand how it's usually meant to be used, but I don't see what throwing a random number in there does exactly.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Enumerable merging with Enumerable
C#CC# / help
4y ago
enumerable.range vs yield return
C#CC# / help
2y ago
CA1860: Avoid using 'Enumerable.Any()' extension method
C#CC# / help
13mo ago