<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/is-random-getitems-the-best-way-to-get-random-items-in-c-12--wpw1v0kgp" -->

---
title: Is Random.GetItems the best way to get random items in...
description: A performance comparison of different ways to retrieve random items from a collection in C#, benchmarking .NET 8's new Random.GetItems method against older...
canonical: https://daily.dev/posts/is-random-getitems-the-best-way-to-get-random-items-in-c-12--wpw1v0kgp
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Is Random.GetItems the best way to get random items in C# 12? | daily.dev
og:description: A performance comparison of different ways to retrieve random items from a collection in C#, benchmarking .NET 8's new Random.GetItems method against older...
og:url: https://daily.dev/posts/is-random-getitems-the-best-way-to-get-random-items-in-c-12--wpw1v0kgp
og:image: https://api.daily.dev/og/posts/wpw1v0KGp.png
og:image:alt: Is Random.GetItems the best way to get random items in C# 12?
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Is Random.GetItems the best way to get random items in C# 12?

**[Code4IT](https://daily.dev/sources/code4it)** · 9 min read · 0 upvotes · 0 comments

## Summary

A performance comparison of different ways to retrieve random items from a collection in C#, benchmarking .NET 8's new Random.GetItems method against older approaches like OrderBy(Guid.NewGuid()), OrderBy(Random.Shared.Next()), and Random.Shuffle. Using BenchmarkDotNet across arrays of 100, 10,000, and 1,000,000 items, GetItems proves fastest and most memory-efficient across all sizes. However, it has a significant drawback: it can return duplicate items, with tests showing only about 65% unique values on average out of 100 draws from 100 distinct items. The conclusion is that GetItems is ideal for speed but unsuitable when duplicate-free results are required, in which case Random.Shuffle is recommended instead.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.code4it.dev/blog/how-to-get-random-items>

## Questions this post answers

### Does Random.GetItems in .NET 8 return duplicate items when selecting from a collection?

Yes, Random.GetItems can return duplicate items because it samples independently rather than without replacement. Testing with 100 distinct items and retrieving 100 items via GetItems showed only about 65% unique values on average across 200 runs, meaning roughly 35% were duplicates. For duplicate-free random selection, Random.Shuffle should be used instead.

_Developers choosing between GetItems and Shuffle for unique sampling can compare trade-offs like this on daily.dev._

### Is Random.GetItems faster than OrderBy(Guid.NewGuid()) for picking random items in C#?

Yes, Random.GetItems is dramatically faster. Benchmarks on arrays of 100, 10,000, and 1,000,000 items showed GetItems outperforming OrderBy(Guid.NewGuid()) by 6.6x to 65x in execution time and using 4x to 8x less memory, since generating a new Guid per item is expensive compared to GetItems' internal sampling approach.

_Anyone benchmarking C# collection operations can track findings like these via daily.dev._

### What is the fastest way to shuffle or randomly select items from an array in C# without duplicates?

Random.Shuffle, introduced alongside Random.GetItems in .NET 8, shuffles an array in place and lets you take the first N items without duplicates, unlike GetItems. Shuffling without copying the array is about 4.5x slower than GetItems but still far faster than OrderBy(Guid.NewGuid()) or OrderBy(Random.Next()), while guaranteeing each element appears only once.

_daily.dev helps developers weighing shuffle versus sampling strategies in .NET stay on top of the details._

## Similar posts on daily.dev

- [C\# Reflection: The Complete .NET 10 Guide](https://daily.dev/posts/c-reflection-the-complete-net-10-guide-xjtayoxme) · We Are .NET · 2 upvotes · 0 comments

---

Tags: [#performance](https://daily.dev/tags/performance), [#.net](https://daily.dev/tags/.net), [#c#](https://daily.dev/tags/c#)

[View this post on daily.dev](https://daily.dev/posts/is-random-getitems-the-best-way-to-get-random-items-in-c-12--wpw1v0kgp)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Is Random.GetItems the best way to get random items in C# 12?","url":"https://daily.dev/posts/is-random-getitems-the-best-way-to-get-random-items-in-c-12--wpw1v0kgp","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/is-random-getitems-the-best-way-to-get-random-items-in-c-12--wpw1v0kgp"},"datePublished":"2026-10-04T13:07:18.193Z","dateModified":"2026-10-04T13:13:43.966Z","description":"A performance comparison of different ways to retrieve random items from a collection in C#, benchmarking .NET 8's new Random.GetItems method against older...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5f07de8fa24c899a68267f611d11b638?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5f07de8fa24c899a68267f611d11b638?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Code4IT","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Code4IT","logo":"https://media.daily.dev/image/upload/s--OaaG4G10--/f_auto,q_auto/v1791119049/logos/code4it?_a=BAMAMicg0","url":"https://daily.dev/sources/code4it"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/is-random-getitems-the-best-way-to-get-random-items-in-c-12--wpw1v0kgp","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"performance,.net,c#","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code4IT","item":"https://daily.dev/sources/code4it"},{"@type":"ListItem","position":3,"name":"Is Random.GetItems the best way to get random items in C# 12?"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/is-random-getitems-the-best-way-to-get-random-items-in-c-12--wpw1v0kgp#faq","mainEntity":[{"@type":"Question","name":"Does Random.GetItems in .NET 8 return duplicate items when selecting from a collection?","acceptedAnswer":{"@type":"Answer","text":"Yes, Random.GetItems can return duplicate items because it samples independently rather than without replacement. Testing with 100 distinct items and retrieving 100 items via GetItems showed only about 65% unique values on average across 200 runs, meaning roughly 35% were duplicates. For duplicate-free random selection, Random.Shuffle should be used instead. Developers choosing between GetItems and Shuffle for unique sampling can compare trade-offs like this on daily.dev."}},{"@type":"Question","name":"Is Random.GetItems faster than OrderBy(Guid.NewGuid()) for picking random items in C#?","acceptedAnswer":{"@type":"Answer","text":"Yes, Random.GetItems is dramatically faster. Benchmarks on arrays of 100, 10,000, and 1,000,000 items showed GetItems outperforming OrderBy(Guid.NewGuid()) by 6.6x to 65x in execution time and using 4x to 8x less memory, since generating a new Guid per item is expensive compared to GetItems' internal sampling approach. Anyone benchmarking C# collection operations can track findings like these via daily.dev."}},{"@type":"Question","name":"What is the fastest way to shuffle or randomly select items from an array in C# without duplicates?","acceptedAnswer":{"@type":"Answer","text":"Random.Shuffle, introduced alongside Random.GetItems in .NET 8, shuffles an array in place and lets you take the first N items without duplicates, unlike GetItems. Shuffling without copying the array is about 4.5x slower than GetItems but still far faster than OrderBy(Guid.NewGuid()) or OrderBy(Random.Next()), while guaranteeing each element appears only once. daily.dev helps developers weighing shuffle versus sampling strategies in .NET stay on top of the details."}}]}
```

