Number Combination

Hello,

I'm trying this program out of self interest. I would like inputs regding where i can start off...

My Reqmt is this:..

If i have 10 nos... 1,2 3,4,5,6,..10...

Everytime i run my program it should generate a different combination of numbers

4 2 5 8 3 ...covering all 10 nos.

next time 5 7 3 9 .. covering all 10 nos.

..so on

This would involve a lot of mathematics i suppose.

Please help

[457 byte] By [Anuradha.Athreyaa] at [2007-10-1 10:17:45]
# 1

I think you are confused with your terminology.

If you have 10 numbers [1-10] and you choose 10 of them, there is only 1 combination to do this. But there are 10! (factorial) permutations.

So you want to generate a different permutation of 10 numbers each time the program is run.

It does not sound like you want to generate all permutations, just a random permutation.

I would probably do something like:

add all numbers to a vector

generate a random index value

remove that number from the vector and add to array

repeat until the vector is empty

or

add all numbers to an array

for each number in the array, swap it with another element in the array at a random index location.

Maybe someone else has a better suggestion.

rkippena at 2007-7-10 2:44:45 > top of Java-index,Other Topics,Algorithms...
# 2
Yes, u got it right .. I need to generate random permutation and not all.. Will try the proposed method n get back to u
Anuradha.Athreyaa at 2007-7-10 2:44:45 > top of Java-index,Other Topics,Algorithms...
# 3
There's alsojava.util.Collections.shuffle(...);
RadcliffePikea at 2007-7-10 2:44:45 > top of Java-index,Other Topics,Algorithms...