dotnet web sql business etc

22 квітня, 2011

Implementation of a simple algorithm to generate a random alpha-numeric string of a needed size

Below is an implementation of a simple algorithm to obtain an alpha-numeric id, I found on the web, neat and easy:

public static string GenerateUniqueCode(int maxSize)
        {
            var allowedChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            var random = new Random();
            var result = new string(
                Enumerable.Repeat(allowedChars, maxSize)
                          .Select(s => s[random.Next(s.Length)])
                          .ToArray());
            return result;
        }

Мітки: , ,

0 коментарі(в):

Дописати коментар

Підписка на Дописати коментарі [Atom]

<< Головна сторінка