Picking some numbers randomly from a pool of integers :-)
Hello!
I want a code to select randomly let's say 3 numbers from a pool of numbers like (1,2,4,7,8,34) which have evenly distributed probabilities.
How this can be done?
I have found only how to pick a number randomly from a range of integers, but this is not my case, as I don't want the possibility of a number being selected more than once. And also I have a 'pool' of integers, not just a range of them :(
Thanks
[451 byte] By [
miss_eleca] at [2007-11-27 10:03:30]

As you pick numbers from the set, you could remove them. Or you could remember the set of numbers chosen so far, and repeat the selection when a chosen value was previously selected. None of this is hard or tricky to do.
I have found in this site http://www.sics.se/humle/socialcomputing/download/javadoc/util/javadoc/se/sics/util/DataTypeUtils.html
a method shuffle(int[] array, Random random) which is exaclty what I look...but do you have any idea of how I can incorporate these in my library? I use JBuilder with 1.4 java version.
What's wrong with using the shuffle method of java.util.Collections?
import java.util.*;
public class ShuffleExample {
public static void main(String... args) {
Integer[] array = {2, 3, 5, 7, 9, 11, 13, 17};
Collections.shuffle(Arrays.asList(array));
System.out.println(Arrays.toString(array));
}
}