List of usage examples for java.util Random nextInt
public int nextInt(int bound)
From source file:com.aqnote.shared.cryptology.util.lang.CommonUtil.java
public static String genRandom(int length) { final int maxNum = ASCII_CHAR.length; int i;/*from w ww . j a va2s.c om*/ int count = 0; Random r = new Random(); StringBuffer pwd = new StringBuffer(""); while (count++ < length) { i = Math.abs(r.nextInt(maxNum)); if (i >= 0 && i < ASCII_CHAR.length) { pwd.append(ASCII_CHAR[i]); } } return pwd.toString(); }
From source file:Main.java
public static String randomString() { Random generator = new Random(); StringBuilder randomStringBuilder = new StringBuilder(); char tempChar; for (int i = 0; i < 32; i++) { tempChar = (char) (generator.nextInt(25) + 97); randomStringBuilder.append(tempChar); }/* w w w. jav a 2 s.c o m*/ return randomStringBuilder.toString(); }
From source file:com.eugene.fithealthmaingit.FatSecretSearchAndGet.FatSecretGetMethod.java
private static String nonce() { Random r = new Random(); StringBuilder n = new StringBuilder(); for (int i = 0; i < r.nextInt(8) + 2; i++) n.append(r.nextInt(26) + 'a'); return n.toString(); }
From source file:fr.esecure.banking.metier.utils.PasswordGenerator.java
public static String genererDefaultPassword() { int n;/*from w w w . j a v a 2s .c om*/ String password = ""; Random r = new Random(); for (int i = 0; i < NChar; i++) { n = r.nextInt(4); // gnere un nombre alatoire entre 0 et 3 if (n == 0) password += maj[r.nextInt(maj.length)]; else if (n == 1) password += min[r.nextInt(min.length)]; else if (n == 2) password += chiffre[r.nextInt(chiffre.length)]; else password += charSpecial[r.nextInt(charSpecial.length)]; } return password; }
From source file:fr.esecure.banking.metier.utils.PasswordGenerator.java
public static String genererDefaultPasswordAndCrypt() { int n;/*w w w .j a v a 2 s. c o m*/ String password = ""; Random r = new Random(); for (int i = 0; i < NChar; i++) { n = r.nextInt(4); // gnere un nombre alatoire entre 0 et 3 if (n == 0) password += maj[r.nextInt(maj.length)]; else if (n == 1) password += min[r.nextInt(min.length)]; else if (n == 2) password += chiffre[r.nextInt(chiffre.length)]; else password += charSpecial[r.nextInt(charSpecial.length)]; } return crypter(password); }
From source file:gr.demokritos.iit.cru.creativity.reasoning.semantic.ThinkingSeedGenerator.java
public static String ThinkingSeedGenerator(String seed, int difficulty, String language) throws ClassNotFoundException, SQLException, IOException, InstantiationException, IllegalAccessException {//from w ww. j a va 2 s .c om ArrayList<String> mined = new ArrayList<String>(); Connect c = new Connect(language); RandomWordGenerator r = new RandomWordGenerator(c); String randomPhrase = r.selectRandomWord(seed, difficulty); int size = randomPhrase.split(",").length; Random rand = new Random(); if (language.equalsIgnoreCase("en")) { while (mined.size() < size) { int Point = rand.nextInt(1172);//number of words in english thesaurus String word = FileUtils.readLines(new File(c.getEnglish_thes())).get(Point).trim(); if (mined.contains(word)) {//|| inf.getStop().contains(word)) { continue; } mined.add(word); } } else if (language.equalsIgnoreCase("de")) { while (mined.size() < size) { int Point = rand.nextInt(1704);//number of words in german thesaurus String word = FileUtils.readLines(new File(c.getGerman_thes())).get(Point).trim(); if (mined.contains(word)) { continue; } mined.add(word); } } else { while (mined.size() < size) { int Point = rand.nextInt(933);//number of words in greek thesaurus String word = FileUtils.readLines(new File(c.getGreek_thes())).get(Point).trim(); if (mined.contains(word)) { continue; } mined.add(word); } } c.CloseConnection(); return StringUtils.join(mined, ","); }
From source file:dtu.ds.warnme.utils.RandomUtils.java
public static String randomString(int minChars, int maxChars) { char[] chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(),./;'[]\\<>?:\"{}|-=_+".toCharArray(); StringBuilder sb = new StringBuilder(); Random random = new Random(); for (int i = 0; i < randomInt(minChars, maxChars); i++) { char c = chars[random.nextInt(chars.length)]; sb.append(c);//from w w w.j a v a 2s .c om } String output = sb.toString(); return output; }
From source file:Main.java
public static String getRandom(int i) { Random jjj = new Random(); // int suiJiShu = jjj.nextInt(9); if (i == 0)// w w w . j a va2s. co m return ""; String jj = ""; for (int k = 0; k < i; k++) { jj = jj + jjj.nextInt(9); } return jj; }
From source file:com.skilrock.lms.common.utility.AutoGenerate.java
public static String autoPassword() { Random r = new Random(); StringBuffer newString = new StringBuffer(); // No of Big letters in password int a1 = r.nextInt(6) + 1; // No of small letters in password int a2 = r.nextInt(7 - a1) + 1; // no on numbers int a3 = 8 - a1 - a2; for (int j = 0; j < a1; j++) { char c1 = (char) (r.nextInt(26) + 65); // AL.add(new Character(c1)); newString.append(new Character(c1)); }/* w w w . ja v a 2s .c om*/ for (int j = 0; j < a2; j++) { char c1 = (char) (r.nextInt(26) + 97); // AL.add(new Character(c1)); newString.append(new Character(c1)); } for (int j = 0; j < a3; j++) { char c1 = (char) (r.nextInt(9) + 48); // AL.add(new Character(c1)); newString.append(new Character(c1)); } //logger.debug("pwd = " + newString.toString()); return newString.toString(); }
From source file:at.alladin.rmbt.qos.testscript.SystemApi.java
public static String getRandomUrl(String prefix, String suffix, int length) { char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; StringBuilder randomUrl = new StringBuilder(); randomUrl.append(prefix);/*from ww w . j av a 2s. c om*/ Random rnd = new Random(); for (int i = 0; i < length; i++) { randomUrl.append(digits[rnd.nextInt(16)]); } randomUrl.append(suffix); return randomUrl.toString(); }