Random Character With LINQ


Just now, I checked my forgotten stackoverflow account. I looked on some common questions and upvoted the good ones. Then I stumbled to this great answer. Why it was so great? Because it solves common problem, just creating random characters, but using such advance thing. I mean people usually just use Random and create character. This awesome man, using LINQ, giving range of characters to create the random set of character. If you are too lazy to see that, you can see the code below.

var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var random = new Random();
var result = new string(
    Enumerable.Repeat(chars, 8)
              .Select(s => s[random.Next(s.Length)])
              .ToArray());

all credits goes to dtb