Advertisement
utroz

NumbersRandom

Jun 21st, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.16 KB | None | 0 0
  1. /** Numbers.java
  2. /* This file is part of Number Random.#
  3. /* Copyright ©2011 - @uthor #Utroz#. */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class Numbers { 
  8.  
  9.     private static int count = 0;
  10.     private static Scanner input = new Scanner(System.in);
  11.  
  12.     private static long totalN = 0;
  13.  
  14.     public Numbers(){} 
  15.  
  16.     public void simpleBrute(){
  17.  
  18.         int a = 0, b = 0, c = 0, d = 0;    
  19.  
  20.         for(a = 0; a <= 9; a++){
  21.  
  22.             for(b = 0; b <= 9; b++){
  23.  
  24.                 for(c = 0; c <= 9; c++){
  25.  
  26.                     for(d = 0; d <= 9; d++){
  27.  
  28.                         ++count;
  29.                         System.out.println(""+a+"|"+b+"|"+c+"|"+d+"\t Current Count: "+count+"");
  30.  
  31.                     } // d.
  32.                 } // c.
  33.             } // b.
  34.         } // a.    
  35.  
  36.     }  
  37.  
  38.     public void forceBrute(){
  39.  
  40.         char[] chars = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','w','y','z'
  41.         ,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','X','W','Y','Z'
  42.         ,'0','1','2','3','4','5','6','7','8','9'};
  43.  
  44.         int a = 0, b = 0, c = 0, d = 0;
  45.  
  46.         for(a = 0; a < chars.length; a++){     
  47.  
  48.             for(b = 0; b < chars.length; b++){
  49.  
  50.                 for(c = 0; c < chars.length; c++){
  51.  
  52.                     for(d = 0; d < chars.length; d++){
  53.  
  54.                         ++count;
  55.                         System.out.println(""+chars[a]+"|"+chars[b]+"|"+chars[c]+"|"+chars[d]+"\t Current Count: "+count+"");
  56.  
  57.                     } // d.
  58.                 } // c.
  59.             } // b.    
  60.         }//a.
  61.     }
  62.  
  63.     public void calculate(){
  64.  
  65.         int a = 0, b = 0, c = 0, d = 0,e = 0,f = 0;
  66.         long[][] array = new long[5000000][6];
  67.  
  68.         int index = 1; // current index of array.
  69.         int nRepeat = 0;
  70.  
  71.         long time = System.currentTimeMillis();
  72.  
  73.         for(a = 1; a <= 60; a++){
  74.  
  75.             if(a == b || a == c || a == d || a == e || a == f) continue;
  76.        
  77.  
  78.             for(b = 1; b <= 60; b++){
  79.  
  80.                 if(b == a || b == c || b == d || b == e || b == f) continue;
  81.            
  82.  
  83.                 for(c = 1; c <= 60; c++){
  84.  
  85.                     if(c == a || c == b || c == d || c == e || c == f) continue;
  86.                
  87.  
  88.                     for(d = 1; d <= 60; d++){
  89.  
  90.                         if(d == a || d == b || d == c || d == e || d == f) continue;
  91.                    
  92.  
  93.                         for(e = 1; e <= 60; e++){
  94.  
  95.                             if(e == a || e == b || e == c || e == d || e == f) continue;
  96.                        
  97.  
  98.                             for(f = 1; f <= 60; f++){
  99.  
  100.                                 if(f == a || f == b || f == c || f == d || f == e) continue;
  101.  
  102.                                 boolean A_ = false, B_ = false, C_ = false, D_ = false, E_ = false, F_ = false;
  103.  
  104.  
  105.                                 // Start on 1, because cont 0 is correct.
  106.  
  107.                                 for(int i = 0; i < array.length; i++){ 
  108.  
  109.                                     A_ = false; B_ = false; C_ = false; D_= false; E_ = false; F_ = false; 
  110.  
  111.                                     if(count == 0){
  112.                                         array[0][0] = a; array[0][1] = b; array[0][2] = c; array[0][3] = d; array[0][4] = e; array[0][5] = f;
  113.                                         break;
  114.  
  115.                                     }
  116.  
  117.                                     if(array[i][0] == 0) break;
  118.  
  119.  
  120.                                     /* This method is to check if this combination is equal with some other. */
  121.  
  122.                                                     //check A.  
  123.  
  124.                                                     for(int j = 0; j < 6; j++){  
  125.  
  126.                                                         if(a == array[i][j]) A_ = true;                                                
  127.                                     }  
  128.  
  129.                                                     //check B.  
  130.  
  131.                                                     for(int j = 0; j < 6; j++){  
  132.  
  133.                                                             if(b == array[i][j]) B_ = true;  
  134.  
  135.                                                     }  
  136.  
  137.                                                     //check C.  
  138.  
  139.                                                     for(int j = 0; j < 6; j++){  
  140.  
  141.                                                             if(c == array[i][j]) C_ = true;  
  142.  
  143.                                                     }  
  144.  
  145.                                                     //check D.  
  146.  
  147.                                                     for(int j = 0; j < 6; j++){  
  148.  
  149.                                                             if(d == array[i][j]) D_ = true;  
  150.  
  151.                                                     }  
  152.  
  153.                                                     //check E.  
  154.  
  155.                                                     for(int j = 0; j < 6; j++){  
  156.  
  157.                                                             if(e == array[i][j]) E_ = true;  
  158.  
  159.                                                     }  
  160.  
  161.                                                     //check F.  
  162.  
  163.                                                     for(int j = 0; j < 6; j++){  
  164.  
  165.                                                             if(f == array[i][j]) F_ = true;  
  166.  
  167.                                                     }  
  168.  
  169.                                     if(A_ == true && B_ == true && C_ == true && D_ == true && E_ == true && F_ == true) break;
  170.  
  171.                                 } // end for.
  172.  
  173.  
  174.                                 long finalTime = System.currentTimeMillis();
  175.  
  176.                                 ++totalN;
  177.  
  178.                                 /* IF this method to be equals jump to next loop. */                       
  179.  
  180.                                 if(A_ == true && B_ == true && C_ == true && D_ == true && E_ == true && F_ == true) {
  181.  
  182.                                     System.out.printf("\t"+a+"|"+b+"|"+c+"|"+d+"|"+e+"|"+f+" |\t Current Count: "+count+" |\t Repeat Numbers :"+nRepeat+" |\t Current Time: %.2f (minutes) |\t Total Number: "+totalN+" |\t ## This combination is repeated! ## \n", (finalTime - time) / 1000f / 60f );
  183.  
  184.                                     nRepeat++;
  185.                                     continue;
  186.  
  187.                                 }
  188.  
  189.                                 if(count != 0){
  190.  
  191.                                     array[index][0] = a; array[index][1] = b; array[index][2] = c; array[index][3] = d; array[index][4] = e; array[index++][5] = f;            
  192.  
  193.                                 }
  194.  
  195.                                 finalTime = System.currentTimeMillis();
  196.  
  197.                                 ++count;
  198.  
  199.                                 System.out.printf("\t"+a+"|"+b+"|"+c+"|"+d+"|"+e+"|"+f+" |\t Current Count: "+count+" |\t Repeat Numbers :"+nRepeat+" |\t Current Time: %.2f (minutes) |\t Total Number: "+totalN+" |\t ## This combination is available! ## \n", (finalTime - time) / 1000f / 60f );
  200.  
  201.                             } // f.
  202.  
  203.                         } // e.
  204.  
  205.                     } // d.
  206.  
  207.                 } // c.
  208.  
  209.             } // b.        
  210.  
  211.         }//a.
  212.     }  
  213.  
  214.     public void print(){
  215.  
  216.         System.out.println("");
  217.         System.out.println("Combinations Amount: "+count+"");
  218.  
  219.         this.count = 0; // reset count.
  220.  
  221.     }  
  222.  
  223.     public static void main(String[] args){    
  224.  
  225.         System.out.println("#############################################");
  226.         System.out.println("# Mega-Sena random Numbers by 'Utroz(RSC)'! #");
  227.         System.out.println("#############################################");
  228.  
  229.         System.out.println("");    
  230.  
  231.         try{       
  232.  
  233.             Numbers num = new Numbers();           
  234.  
  235.             while(true){
  236.  
  237.                 System.out.println(" Main Menu:");
  238.                 System.out.println("------------");        
  239.  
  240.                 System.out.println("- Mega Sena [0]\n- Force Brute [1]\n- Simple Brute [2]\n\nPlease input a option:");
  241.  
  242.                 int option = input.nextInt();
  243.                
  244.  
  245.                 int start = 5;
  246.  
  247.                 while(start >= 0){
  248.  
  249.                     Thread.sleep(1200);
  250.  
  251.                     System.out.println("Remaining "+start+" seconds to start system...");
  252.                     start--;
  253.  
  254.                 }
  255.  
  256.                 System.out.println("");
  257.                 System.out.println("# Starting!... #");
  258.  
  259.                 Thread.sleep(3000);
  260.  
  261.                 long time = System.currentTimeMillis();  
  262.  
  263.                 switch(option){
  264.  
  265.                     case 0:
  266.                         num.calculate();
  267.  
  268.                         num.print();
  269.  
  270.                         break;
  271.  
  272.                     case 1:
  273.                         num.forceBrute();
  274.  
  275.                         num.print();
  276.  
  277.                         break;                     
  278.  
  279.                     case 2:
  280.                         num.simpleBrute();
  281.  
  282.                         num.print();
  283.  
  284.                         break;                     
  285.  
  286.                     default: System.out.println("Please input a valid option!");                       
  287.  
  288.                 }
  289.  
  290.                 long finalTime = System.currentTimeMillis();
  291.  
  292.                 System.out.printf("Time used in processing: %.2f seconds.\n", (finalTime - time) / 1000f / 60f );
  293.  
  294.             }
  295.  
  296.         } catch(InterruptedException ex){
  297.  
  298.         }      
  299.  
  300.     }
  301.  
  302. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement