SecureRandom random = SecureRandom.getInstance("SHA1PRNG");  byte[] intbytes = new byte[4];  for (int i = 0; i < length; ++i) { random.nextBytes(intbytes); pwd[i] = pwdChars[Math.abs(getIntFromByte(intbytes) % pwdChars.length)]; }
SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); byte[] intbytes = new byte[4]; char[] pwd = new char[length];  do { for (int i = 0; i < length; ++i) { random.nextBytes(intbytes); pwd[i] = pwdChars[Math.abs(getIntFromByte(intbytes) % pwdChars.length)]; } password = new String(pwd); } while (password.indexOf('\'') != -1);
    private static final String generatePassword(int length) throws RemoteException, HibernateException {        char[] pwd = new char[length];         try {             SecureRandom random = SecureRandom.getInstance("SHA1PRNG");                         byte[] intbytes = new byte[4];                               for (int i = 0; i < length; ++i) {                 random.nextBytes(intbytes);                 pwd[i] = pwdChars[Math.abs(getIntFromByte(intbytes) % pwdChars.length)];             }         }         catch (Exception ex) {             // Don't really worry, we won't be using this if we can't use securerandom anyway         }         return new String(pwd);     }