CodePudding user response:
For example
Import the Java. Util. HashSet;
Import the Java. Util. Random;
Import the Java. Util. Set;
Public class Sample {
Public static void main (String [] args) {
Char [] keys="0123456789 abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz". ToCharArray ();
The Random ran=new Random ();
SetThe set=new HashSet<> (a);
The StringBuilder buf=new StringBuilder ();
While (set. The size () & lt; 10) {
Buf. Delete (0, buf. Length ());
for (int i=0; I & lt; 6; I++) {
Buf. Append (keys [ran nextInt (keys) length)]);
}
String s=buf. ToString ();
if (! The set contains (s)) {
Set. The add (s);
}
}
For (String s: set) {
System. The out. Printf (" random authentication code: % s \ n ", s);
}
}
}