Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Date;
- import java.util.Random;
- public class TimeChacker {
- private static Random random = new Random((new Date()).getTime());
- public static String generateRandomString(int length) {
- char[] values = {'a','b','c','d','e','f','g','h','i','j',
- 'k','l','m','n','o','p','q','r','s','t',
- 'u','v','w','x','y','z'};
- String out = "";
- for (int i=0;i<length;i++) {
- int idx=random.nextInt(values.length);
- out += values[idx];
- }
- return out;
- }
- public static String formatInt(int n, int digits) {
- /*
- we create a format :
- %% : % the first % is to escape the second %
- 0 : 0 zero character
- %d : how many '0' we want (specified by digits)
- d : d the number to format
- */
- String format = String.format("%%0%dd", digits);
- return String.format(format, n);
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int result=0;
- String pass = "";
- int tries=0;
- Random numbers = new Random();
- while(pass!="abc1234"){
- result = numbers.nextInt(9999);
- pass = generateRandomString(3) + formatInt(result, 4);
- tries++;
- System.out.println(pass);
- }
- System.out.println("There Was: " + tries + "Tries");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment