Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

generate random string in java

import java.util.Random;

public class Generator {
	public static String generateRandomPassword(int len) {
		String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk"
          +"lmnopqrstuvwxyz!@#$%&";
		Random rnd = new Random();
		StringBuilder sb = new StringBuilder(len);
		for (int i = 0; i < len; i++)
			sb.append(chars.charAt(rnd.nextInt(chars.length())));
		return sb.toString();
	}
}
Comment

java random string

public static String getRandomString(int size) {
  	// The string that we will return
	String rand = "";
  	// The chars that are used to generate the random string
	String chars = "1234567890-=!@#$%^&*()_+qwertyuiop[]QWERTYUIOP{}|asdfghjkl;'ASDFGHJKL:"zxcvbnm,./ZXCVBNM<>?";
  	// Loop based on the requested size
  	for (int i = 0; i < size; i++) {
      	// Add a random char from the chars string to the rand string
		rand += chars.toCharArray()[new Random().nextInt(chars.length())];
	}
  	// Return the random string
	return rand;
}
Comment

generate 5 digit random string in java

RandomStringUtils.randomAlphanumeric(17).toUpperCase()
Comment

java random string


protected String getSaltString() {
        String SALTCHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
        StringBuilder salt = new StringBuilder();
        Random rnd = new Random();
        while (salt.length() < 18) { // length of the random string.
            int index = (int) (rnd.nextFloat() * SALTCHARS.length());
            salt.append(SALTCHARS.charAt(index));
        }
        String saltStr = salt.toString();
        return saltStr;

    }

Comment

java generate random string and number

import java.util.Random;

public class passGen{
    // Version 1.0
    private static final String dCase = "abcdefghijklmnopqrstuvwxyz";
    private static final String uCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final String sChar = "!@#$%^&*";
    private static final String intChar = "0123456789";
    private static Random r = new Random();
    private static StringBuilder pass = new StringBuilder();

    public static void main (String[] args) {
        System.out.println ("Generating pass...");
        while (pass.length () != 16){
            int rPick = r.nextInt(4);
            if (rPick == 0){
                int spot = r.nextInt(26);
                pass.append(dCase.charAt(spot));
            } else if (rPick == 1) {
                int spot = r.nextInt(26);
                pass.append(uCase.charAt(spot));
            } else if (rPick == 2) {
                int spot = r.nextInt(8);
                pass.append(sChar.charAt(spot));
            } else {
                int spot = r.nextInt(10);
                pass.append(intChar.charAt(spot));
            }
        }
        System.out.println ("Generated Pass: " + pass.toString());
    }
}
Comment

java random string

public static String randomString() {
    return UUID.randomUUID().toString();
}
Comment

java generate random string and number

// "0123456789" + "ABCDE...Z"
String validCharacters = $('0', '9').join() + $('A', 'Z').join();

String randomString(int length) {
    return $(validCharacters).shuffle().slice(length).toString();
}

@Test
public void buildFiveRandomStrings() {
    for (int i : $(5)) {
        System.out.println(randomString(12));
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java sort array int 
Java :: java string start with substring 
Java :: java union type 
Java :: result set methods 
Java :: how to be good at javasctript 
Java :: java, how to find the most repeated character 
Java :: @runwith junit 5 
Java :: taglib in jsp 
Java :: x = x + y; in java 
Java :: what is java steam 
Java :: get image from resourcestream javafx 
Java :: jgit clone in memory 
Java :: why does the ribbon dependency crush my app 
Sql :: safe update mysql 
Sql :: today minus 15 days postgresql 
Sql :: postgres get columns names 
Sql :: how to truncate table with foreign key constraint 
Sql :: turn on foreign keys check mysql 
Sql :: grant revoke privileges to mysql username 
Sql :: mysql list databases 
Sql :: mysql grant all privileges to a user 
Sql :: start mysql server by terminal in linux 
Sql :: restart postgresql.service Failed to restart postgresql.service: Unit not found. 
Sql :: rename column oracle 
Sql :: convert_tz mysql 
Sql :: find names starting with vowels in sql 
Sql :: add sequence postgres 
Sql :: how to show all users in mysql 
Sql :: how to check all scheduled jobs in oracle 
Sql :: bulk kill mysql processlist 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =