Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

generate 5 digit random string in java

RandomStringUtils.randomAlphanumeric(17).toUpperCase()
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 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 :: how to call intent in adapter class in android 
Java :: jframe border 
Java :: onclick listener android 
Java :: counting nodes in binary search tree 
Java :: Java Scanner nextLine() 
Java :: how to change label text color javafx 
Java :: java return list 
Java :: android checkbox tint color 
Java :: How to remove backstack fragment 
Java :: java main method 
Java :: java string to lower case 
Java :: convert date to offsetdatetime in java 
Java :: How to create a popup window (PopupWindow) in Android 
Java :: How to swap two values in Java using a supporting method? 
Java :: java.lang.IllegalArgumentException: Invalid character found in method name 
Java :: java put a char array into a string 
Java :: Java how to make a number without a digit 
Java :: java list distinct by object attribute 
Java :: java syntax for object creation 
Java :: java join two list 
Java :: java dynamic method dispatch 
Java :: java.math.biginteger cannot be cast to java.lang.long 
Java :: java for increment by 2 
Java :: string vs stringbuffer 
Java :: How to find the prime factors of a number in Java? 
Java :: copy constructor in java 
Java :: char to unicode java 
Java :: how to remove null values collections 
Java :: java get first day of the week 
Java :: how to get color from resource android 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =