[Solved] how to make random loop for array [closed]


It seems you just want to shuffle the characters and generate a new string.You can use the method that uses Fisher-Yates shuffle algorithm (from this answer, I modified it little bit for your situation):

public static void Shuffle<T>(this T[] source)  
{  
    Random rng = new Random();  
    int n = source.Length; 
    while (n > 1) {  
        n--;  
        int k = rng.Next(n + 1);  
        T value = source[k];  
        source[k] = source[n];  
        source[n] = value;  
    }  
}

Then just use it:

string s = "qweasdzxc";
char[] chars = s.ToCharArray();
chars.Shuffle();
string random = new string(chars);

Also remember that this is an extension method so you need to put it into a public and static class.

2

solved how to make random loop for array [closed]