CSharp · Console
using System;
using System.Threading;
public class Program
{
public static void Main()
{
var x = 100;
while (x-- > 0)
{
Console.WriteLine(Generate());
}
}
private static Random rnd = new Random();
private static char[] alphabet = new char[]
{
'a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z'
};
public static string Generate(int length = 7)
{
var prev = '#'; // initialize with non-possible char
var count = 0;
var result = new char[length];
while (count < length)
{
var idx = rnd.Next(alphabet.Length);
var next = alphabet[idx];
if (prev != next)
{
result[count++] = next;
prev = next;
}
}
return new string(result);
}
}