Random string consists of random characters.
import java.util.Random;
public class Main {
public static void main(String[] argv) {
System.out.println(randomString(10));
}
public static String randomString(int length) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < length; i++) {
b.append(base.charAt(random.nextInt(base.length())));
}
return b.toString();
}
private static String base = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabsdefghijklmnopqrstuvwxyz";
private static Random random = new Random();
}
Output:
TZmhxoWE1f
Home
Java Book
Runnable examples
Java Book
Runnable examples
Math:
- Convert between polar and rectangular coordinates
- Random bytes
- Random boolean
- Random integer between lo and hi interval
- Random long type number
- Random numbers between 1 and 100
- Random number between 0 AND 10
- Random integers that range from from 0 to n
- Random string consists of random characters.
- Random array of numbers
- Round float and double numbers
- Round to ceiling
- Round to floor value