By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,571 Members | 1,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,571 IT Pros & Developers. It's quick & easy.


P: n/a
I have Array of 50 ints. I want to receive random permutation, so
in each int will be different number from 0-49.
Is there any class for permutation ?


Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a

I'm not completely sure I understand your question.
I don't think there are any Permutation classes in .Net,
but will this code give you what you seek?

Random rand = new Random();
ArrayList numbers = new ArrayList();
int[] permutation = new int[50];

// create a list that holds the numbser 0, 1, 2 ... 49
for(int i = 0; i < permutation.Length; i++)

// for each entry in the permutation list
// grab the number from a random position in the number list
for(int i = 0; i < permutation.Length; i++)
int o = rand.Next(numbers.Count);
permutation[i] = (int)numbers[o];

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.