.NET 8 Adds Shuffle to Random for Arrays and Spans

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 พ.ย. 2023
  • 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 8 หลายเดือนก่อน +7

    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  8 หลายเดือนก่อน +1

      That would be nice.

    • @benjaminshinar9509
      @benjaminshinar9509 7 หลายเดือนก่อน +1

      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 8 หลายเดือนก่อน +1

    Good content and you've got to keep up with the Jones.

  • @luke2v52
    @luke2v52 8 หลายเดือนก่อน

    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  8 หลายเดือนก่อน +2

      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 8 หลายเดือนก่อน

    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  8 หลายเดือนก่อน +1

      Thanks for sharing!

  • @hqcart1
    @hqcart1 8 หลายเดือนก่อน +1

    how to create a new shuffled list and keep the original one in the same order?

    • @KeyboardKrieger
      @KeyboardKrieger 8 หลายเดือนก่อน +5

      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.

  • @adam-xt8te
    @adam-xt8te 8 หลายเดือนก่อน

    Mr Corey, do you have plan for making tutorial about publishing apps in MS Store?

    • @IAmTimCorey
      @IAmTimCorey  7 หลายเดือนก่อน

      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/

  • @FAHADBINYOUSUF
    @FAHADBINYOUSUF 7 หลายเดือนก่อน

    do you have any video on ABP Framework and .net Zero?

    • @IAmTimCorey
      @IAmTimCorey  7 หลายเดือนก่อน

      Nope, not yet. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/

  • @sbraudrick
    @sbraudrick 8 หลายเดือนก่อน

    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  8 หลายเดือนก่อน

      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.