由于您不将其用作键,仅仅是随意使用字符串,您可以在Java中使用此程序:
import java.util.Random;
public class randomString {
public static void main(String args[]) {
Random charp = new Random();
String[] chars = {"a", "b", "c", "d", "e", "f", "g", "h" ,"i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "M", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
String[] word = new String[9];
for(int i = 0; i < 9;i++) {
word[i] = chars[charp.nextInt(70)];
}
System.out.print("Your randomly generated string is: ");
for(int i = 0; i < 9;i++) {
System.out.print(word[i]);
}
}
}
我知道这有点低级,还有许多其他的库和代码,比如:
import java.security.SecureRandom;
import java.math.BigInteger;
可以使用,但是我们也可以保持简单。