How can I generate random alphanumeric strings?
.net, c#, random
Solution
I heard LINQ is the new black, so here's my attempt using LINQ:
private static Random random = new Random();
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
(Note: The use of the `Random` class makes this unsuitable for anything security related, such as creating passwords or tokens. Use the `RNGCryptoServiceProvider` class if you need a strong random number generator.)
Problem
How can I generate a random 8 character alphanumeric string in C#?
Related problems
- Unique random string generation
- How to make random string of numbers and letters with a length of 5?
- Random String Generator Returning Same String
- What is Medium Trust in Asp.net?
- using RNGCryptoServiceProvider to generate random string
- Eliminating modulo bias: how is it achieved in the arc4random_uniform() function?
- Cryptograhically random unique strings