CSharp examples for System:Random
Generates a random string
// Licensed under the Apache License, Version 2.0 (the "License"); using System.Globalization; using System.Linq; using System.Text.RegularExpressions; using System.Text; using System.Security.Cryptography; using System.Collections.Generic; using System;/*from www.j a v a 2 s . co m*/ public class Main{ /// <summary> /// Generates a random string /// </summary> /// <param name="length"></param> /// <returns></returns> public static string RandomString(int length) { byte[] randBuffer = new byte[length]; RandomNumberGenerator.Create().GetBytes(randBuffer); return System.Convert.ToBase64String(randBuffer).Remove(length); } }