Answers for "random string generator"

14

Generate Random String

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());
}
Posted by: Guest on June-14-2020
10

Javascript generate random string

function getRandomString(length) {
    var randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var result = '';
    for ( var i = 0; i < length; i++ ) {
        result += randomChars.charAt(Math.floor(Math.random() * randomChars.length));
    }
    return result;
}

//usage: getRandomString(20); // pass desired length of random string
Posted by: Guest on July-23-2019
0

A random character from a string of characters:

String chars = "abcxyz";
Random rnd = new Random();
char c = chars.charAt(rnd.nextInt(chars.length()));
Posted by: Guest on December-19-2020

Code answers related to "random string generator"

Code answers related to "Javascript"

Browse Popular Code Answers by Language