Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
method for shuffling elements of an array
Turkalp Kucur
Oct 29 2012 5:50 AM
1.6k
Reply
Hello my friends.
I need a method which takes an array of element than returns it with elements which are in randomized order.
For that purpose I developed following method
string[] shuffle(string[] a)
{
for (int i = 0; i < a.Length; i++)
{
string tmp = a[i];
int randomnumber = rnd.Next(i, a.Length);
a[i] = a[randomnumber];
a[randomnumber] = tmp;
}
return a;
}
but it returns sometimes the duplicate elements, which is wrong.
I need help.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
How to select toolStripSplitButton using keyboard shortcut?
how to make a bill using c#