There are many ways to virtually "shuffle". Here is one simple example in C#:
static void Shuffle(string[] items, int numTimesToShuffle)
{
// Create a random number generator
Random random = new Random();
// Loop over the array swapping random elements
for (int i = 0; i < numTimesToShuffle; i++)
{
// Pick two indexes in the array to swap
int r1 = random.Next(items.Length);
int r2 = random.Next(items.Length);
// Swap the two elements
string temp = items[r1];
items[r1] = items[r2];
items[r2] = temp;
}
}
Thanks,
Luke Hoban
Visual C# IDE Program Manager
Error 3 Property or indexer 'string.this[int]' cannot be assigned to -- it is read only path\to\Program.cs 70 17 ProjectName
Here is my code:
static string scrambleText(string scText) { Random rand = new Random(); for (int i = 0; i < scText.Length; i++) int swap = rand.Next(i, scText.Length); temp = scText[ i]; |