Advertisement
nRikee

shuffle

Feb 19th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. public class Lista {
  2.     String[] li;
  3.     int size, max, maxIni;
  4.    
  5.     public Lista(){
  6.         li = new String[10];
  7.         size = 0;
  8.         max = maxIni = 10;
  9.     }
  10.         public void shuffle(){
  11.             Integer[] bf = new Integer[size];
  12.             String[] ret = new String[size];
  13.             Random rand = new Random();
  14.             int r=0;
  15.             boolean bool;
  16.        
  17.             for     ( int a=0; a<size; a++ ){
  18.                bool = true;
  19.                while ( bool ){
  20.                    bool = false;
  21.                    r       = rand.nextInt(size);
  22.                    for ( int b=0; b<a; b++ )
  23.                        if( r==bf[b] ) bool = true;
  24.             }
  25.                 bf[a]   = r;
  26.                 ret[a]  = (String) li[r];
  27.             }
  28.         li = ret;
  29.     }
  30.  
  31. // Mรกs metodos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement