Answer the question
In order to leave comments, you need to log in
How to randomize a string?
Hey!
How to randomize a string in seasharp?
I'll show you with an example.
There is a line: toster cool
You need to get as many variations as possible.
Result: toSsster Cooool, ttosterr-ccoool, etc.
How to do it? Thanks for the tip
Answer the question
In order to leave comments, you need to log in
If I understood correctly:
public static string RandomizeString(string str)
{
var chars = str.ToArray();
var random = new Random();
for(int n = chars.Length-1; n>=0; n--)
{
var randomNumber = random.Next(chars.Length);
var savedChar = chars[randomNumber];
chars[randomNumber] = chars[n];
chars[n] = savedChar;
}
return new string(chars);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question