1.首先定义一个需要获取指定范围的字符串

generateSource =  "0123456789abcdefghigklmnopqrstuvwxyz&$@";

2.定义想要获得随机字符串的长度

 int len = 10;

3.循环随机获得每一次的长度

String randStr = "";
for (int i = 0; i < len; i++) {

    //循环随机获得当次字符,并移走选出的字符
   

String nowStr = String.valueOf(generateSource.charAt((int) Math.floor(Math.random() *generateSource.length())));
     randStr += nowStr;
     generateSource =  generateSource .replaceAll(nowStr, "");}
System.out.println(randStr);