Generates a random string with the given length
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Text; namespace Inventory.Test.Library.Plugin { public class GenerateDatesPlugin { private static Random random = new Random((int)DateTime.Now.Ticks);//thanks to McAden /// <summary> /// Generates a random string with the given length /// </summary> /// <param name="size">Size of the string</param> /// <param name="lowerCase">If true, generate lowercase string</param> /// <returns>Random string</returns> private string RandomString(int size) { StringBuilder builder = new StringBuilder(); char ch; for (int i = 0; i < size; i++) { ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))); builder.Append(ch); } return builder.ToString(); } /// <summary> /// Generates a random string with the given length /// </summary> /// <param name="size">Size of the string</param> /// <param name="lowerCase">If true, generate lowercase string</param> /// <returns>Random string</returns> private string RandomNumbersString(int size) { StringBuilder builder = new StringBuilder(); int ch; for (int i = 0; i < size; i++) { ch = random.Next(9); builder.Append(ch); } return builder.ToString().Substring(0, size); } } }