0

Okay so I was converting something from JS into C# (chess algorithm) and after some considerable thinking I had no idea how to convert this specific line :
children.sort(function(a, b){return 0.5 - Math.random()});

Sorry if this sounds stupid but I am mediocre at best at C# and I was trying my best but this really confused me lol

P.S: if its of any use, a and b are not defined anywhere else in the code.

Tweaked around with it, basically hoping that it would work but it did not since idk how to convert the function(a, b) part into C#

Edit: Sorry but I forgot to include, the thing I am converting is for a challenge which is limited to .NET 6.0 and these namespaces:

System
System.Numerics
System.Collections.Generic
System.Linq
ChessChallenge.API (from the challenge)
Marki1234
  • 11
  • 1
  • 2
    It's just a random sort. `a` and `b` are the 2 values which are compared with each other. These are not used in the sorting algorithm since the sorting is randomized. See the [documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) for a full explenation. – Mark Baijens Aug 11 '23 at 09:45
  • .Net8 will have a [Random.Shuffle](https://learn.microsoft.com/en-us/dotnet/api/system.random.shuffle?view=net-8.0) method. If you are not on 8 yet (it *is* still preview), then search for a "shuffle" function – Hans Kesting Aug 11 '23 at 09:55
  • 3
    Does this answer your question? [Randomize a List](https://stackoverflow.com/questions/273313/randomize-a-listt) in particular [@user453230's answer](https://stackoverflow.com/a/4262134/592958) – phuzi Aug 11 '23 at 09:57

0 Answers0