.NET 8 Adds Shuffle to Random for Arrays and Spans

  Рет қаралды 6,619

IAmTimCorey

IAmTimCorey

6 ай бұрын

In .NET 8, we now have a method to randomly shuffle arrays and spans. Let's look at it in this episode of 10 minute training.
Full Training Courses: IAmTimCorey.com
Source Code: leadmagnets.app/?Resource=Ran...
Mailing List: signup.iamtimcorey.com/

Пікірлер: 17
@Sander-Brilman
@Sander-Brilman 6 ай бұрын
crazy they didn't add a overload for a list considering it is backed by an array anyways, oh well. thanks for the video Tim.
@IAmTimCorey
@IAmTimCorey 6 ай бұрын
That would be nice.
@benjaminshinar9509
@benjaminshinar9509 6 ай бұрын
I think it probably has something to do with garbage collection. both arrays and span are stack allocated. maybe the shuffling would mess up the reference tree if it was allocated on the heap.
@user-hn1dz7pe7k
@user-hn1dz7pe7k 6 ай бұрын
Good content and you've got to keep up with the Jones.
@IAmTimCorey
@IAmTimCorey 6 ай бұрын
Thanks.
@luke2v52
@luke2v52 6 ай бұрын
Howdy Tim! I was wondering if you were planning on updating the course website to use the new blazor or if you were going to continue without it. I ask since I have watched the why not blazor video on the iamtimcorey website course and it seems the new blazor might work out now.
@IAmTimCorey
@IAmTimCorey 6 ай бұрын
I’m debating if I redo it using Blazor or not. There are compelling reasons both ways. I’m going to take some time to consider the options. After that, I’ll publish something about the process at least.
@PerryCodes
@PerryCodes 6 ай бұрын
I JUST needed something like this in a little utility that I'm using to learn the guitar fretboard... notes, chords, scales, and arpeggios - that sort of thing - and simply using .NET Random.Next() wasn't creating a good distribution (or maybe it was TOO good! Being asked to "Find the C on the A string" 4 times in a row... not ideal!), so I took to the interwebs to see what some options would be. This led me to learning about Fisher-Yates, Durstenfeld, and a reminder that one of these days, I should really make a better effort to get further than the first 50 pages of The Art of Computer Programming, because Knuth has a little something to say about algorithms! Anyways - creative use of a good ol' Shuffle provided a useful distribution of "random" objects.
@IAmTimCorey
@IAmTimCorey 6 ай бұрын
Thanks for sharing!
@sbraudrick
@sbraudrick 6 ай бұрын
There's no such thing as random when dealing with binary, there's always a seed. I'm interested what seed was used in this function. (I'm not suggesting you left anything out.) But there must be a seed whether it be time, some screwy calculation based on time, where the processor is in cycle count, etc... but there is no true random in computing, just a random you can't figure out in that carbon based thing in your head..... but this was cool to learn about and keep up the awesome content!
@IAmTimCorey
@IAmTimCorey 6 ай бұрын
There's no such thing as generated random numbers. That's why Cloudflare uses 100 lava lamps to generate random numbers. However, for most cases, the Random library in C# works just fine (just not for cryptography). In .NET 6+, the Random library was upgraded to include the static Shared option. This is a thread-safe way to generate pseudo-random numbers in C# now. We don't get to set the seed value, though. If you want to do that, you would instantiate your own version of the Random class instead. As for what specific seed value it uses to start out, I'm not sure.
@adam-xt8te
@adam-xt8te 6 ай бұрын
Mr Corey, do you have plan for making tutorial about publishing apps in MS Store?
@IAmTimCorey
@IAmTimCorey 6 ай бұрын
Not at this time. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
@hqcart1
@hqcart1 6 ай бұрын
how to create a new shuffled list and keep the original one in the same order?
@KeyboardKrieger
@KeyboardKrieger 6 ай бұрын
Personally I would clone the existing list and shuffle the new one. That's at least how I do it in card games for the deck.
@FAHADBINYOUSUF
@FAHADBINYOUSUF 6 ай бұрын
do you have any video on ABP Framework and .net Zero?
@IAmTimCorey
@IAmTimCorey 5 ай бұрын
Nope, not yet. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
Collection Expressions in .NET 8
6:34
IAmTimCorey
Рет қаралды 12 М.
Primary Constructors in .NET 8
28:42
IAmTimCorey
Рет қаралды 21 М.
Универ. 10 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:04:59
Комедии 2023
Рет қаралды 1,1 МЛН
World’s Deadliest Obstacle Course!
28:25
MrBeast
Рет қаралды 48 МЛН
100❤️
00:20
Nonomen ノノメン
Рет қаралды 69 МЛН
Should I Build a Monolith or Microservices?
15:49
IAmTimCorey
Рет қаралды 9 М.
Dependency Injection Updates in .NET - Keyed Implementations
8:31
A Simple Kafka and Python Walkthrough
11:34
Quix
Рет қаралды 6 М.
The Fastest Way to Modify a List in C# | Coding Demo
10:30
Zoran Horvat
Рет қаралды 20 М.
Solving One of the Biggest Array Issues in C#
10:36
Nick Chapsas
Рет қаралды 34 М.
Separating AI Hype from AI Reality
19:49
IAmTimCorey
Рет қаралды 8 М.
All Rust features explained
21:30
Let's Get Rusty
Рет қаралды 283 М.
The New Way of Calling Your Code in .NET 8 Is INSANE
12:34
Nick Chapsas
Рет қаралды 133 М.
Универ. 10 лет спустя - ВСЕ СЕРИИ ПОДРЯД
9:04:59
Комедии 2023
Рет қаралды 1,1 МЛН