Re: OT Friday - Random sorting
Mark Benussi wrote: I am trying to write a comparator that randomly sorts a collection. I'm not entirely convinced that the word "sort" it applicable here. Collections.shuffle might do what you want if you have a List. Dave - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: OT Friday - Random sorting
i may be missing something here, but if random is what u want in a collection, then y don't u use Collections.shuffle() ? riyaz Mark Benussi wrote: Hello. I am trying to write a comparator that randomly sorts a collection. I have something like this: new Comparator() { /** * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(Object object1, Object object2) { long time = new Date().getTime(); Random random1 = new Random(time); Integer x1 = new Integer(random1.nextInt()); random1.setSeed(++time); Integer x2 = new Integer(random1.nextInt()); return x1.compareTo(x2); } } But sadly to no avail. Has anyone done this before or have any suggestions. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
OT Friday - Random sorting
Hello. I am trying to write a comparator that randomly sorts a collection. I have something like this: new Comparator() { /** * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(Object object1, Object object2) { long time = new Date().getTime(); Random random1 = new Random(time); Integer x1 = new Integer(random1.nextInt()); random1.setSeed(++time); Integer x2 = new Integer(random1.nextInt()); return x1.compareTo(x2); } } But sadly to no avail. Has anyone done this before or have any suggestions.