You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@excalibur.apache.org by Holger Klawitter <li...@klawitter.de> on 2005/06/03 10:06:00 UTC

Re: OT Friday - Random sorting

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.

I'd just use java.util.Collections.shuffle().

-- 
With Kind Regards / Mit freundlichem Gruß
  Holger Klawitter (listen <at> klawitter <dot> de)


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@excalibur.apache.org
For additional commands, e-mail: user-help@excalibur.apache.org


RE: OT Friday - Random sorting

Posted by Mark Benussi <ma...@hotmail.com>.
Even better, thank you!

-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Holger Klawitter
Sent: 03 June 2005 09:06
To: tomcat-user@jakarta.apache.org
Cc: user@excalibur.apache.org
Subject: Re: OT Friday - Random sorting

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.

I'd just use java.util.Collections.shuffle().

-- 
With Kind Regards / Mit freundlichem Gruß
  Holger Klawitter (listen <at> klawitter <dot> de)


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@excalibur.apache.org
For additional commands, e-mail: user-help@excalibur.apache.org


RE: OT Friday - Random sorting

Posted by Mark Benussi <ma...@hotmail.com>.
Even better, thank you!

-----Original Message-----
From: news [mailto:news@sea.gmane.org] On Behalf Of Holger Klawitter
Sent: 03 June 2005 09:06
To: tomcat-user@jakarta.apache.org
Cc: user@excalibur.apache.org
Subject: Re: OT Friday - Random sorting

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.

I'd just use java.util.Collections.shuffle().

-- 
With Kind Regards / Mit freundlichem Gruß
  Holger Klawitter (listen <at> klawitter <dot> de)


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org