Home > Back-end >  Strives for the big help
Strives for the big help

Time:10-03

In Java, generate 10 groups randomly 6 digit code

CodePudding user response:

 
The Random rand=new Random ();
for(int i=0; i<10; I++) {
System. The out. Print (rand. NextInt (1000000) + "");
}

Oh remember junction post

CodePudding user response:

Like this?
 int [] arr=new int [10]. 
Int res=0;
for (int i=0; I & lt; Arr. Length; I++)
{
Res=100000 + (int) (Math. The random () * 900000);
Arr [I]=res;
}

CodePudding user response:

1/f, reference source is a ghost reply:
 
The Random rand=new Random ();
for(int i=0; i<10; I++) {
System. The out. Print (rand. NextInt (1000000) + "");
}

Oh remember junction post

How to add contain lowercase letters, eldest brother

CodePudding user response:

refer to the second floor Little5 response:
like this?
 int [] arr=new int [10]. 
Int res=0;
for (int i=0; I & lt; Arr. Length; I++)
{
Res=100000 + (int) (Math. The random () * 900000);
Arr [I]=res;
}

Can be combined with lowercase letters

CodePudding user response:

1/f, reference source is a ghost reply:
 
The Random rand=new Random ();
for(int i=0; i<10; I++) {
System. The out. Print (rand. NextInt (1000000) + "");
}

Oh remember junction post

You have a problem that ha, others are all 6 digits,

CodePudding user response:

reference weixin_46383888 reply: 3/f
Quote: reference source is ghost reply: 1/f,
 
The Random rand=new Random ();
for(int i=0; i<10; I++) {
System. The out. Print (rand. NextInt (1000000) + "");
}

Oh remember junction post

How do add contain lowercase letters, eldest brother

Using random get subscript arrays, implement random gain of the characters

CodePudding user response:

Can you perform a try, come out should be 6 digits

CodePudding user response:

reference 5 floor Little5 reply:
Quote: 1/f, reference source is a ghost reply:

 
The Random rand=new Random ();
for(int i=0; i<10; I++) {
System. The out. Print (rand. NextInt (1000000) + "");
}

Oh remember junction post

You have a problem that ha, others are all 6 digits,

Can you perform a try, come out should be six figures,

CodePudding user response:

reference source is a ghost dao eighth floor response:
Quote: refer to the 5 floor Little5 response:
Quote: reference source is ghost reply: 1/f,

 
The Random rand=new Random ();
for(int i=0; i<10; I++) {
System. The out. Print (rand. NextInt (1000000) + "");
}

Oh remember junction post

You have a problem that ha, others are all 6 digits,

Can you perform a try, come out should be six figures,

Not all is six figures

CodePudding user response:

 
/* *
* 0 ~ 9 a to z a to z random-string generator
*
* @ param scale
* the length of the string
* @ param count
* string quantity
* @ return result sets
* @ the date 2020-03-28 19:38:07
*/
Public static List RandomStr (int scale, int count)
{
The StringBuilder sb=new StringBuilder ();
String strNum="0123456789";
String strCh="abcdefghijklmnopqrstuvwxyz";
Sb. Append (strNum). Append (strCh). Append (strCh. The toUpperCase ());//0 ~ 9 a to z a to z

List Res=new ArrayList<> (a);
Int index=0;
Char [] ch=new char (scale);
While (0!=the count -)
{
for (int i=0; I & lt; Ch. Length; I++)
{
Index=(int) (Math. The random () * sb in length ());//generation 0 to sb. Length random number () - 1
Ch [I]=sb. CharAt (index);
}
Res. The add (String. The valueOf (ch));
}
return res;//size of the count
}

 System. Out. Println (RandomStr (6, 10)); 
//[uY73SU, 1 etcqk WsBbT6, five w73l3 dB5Zz1, mJQaHA, 4 r1nby KKDLLZ, NKHMjR, KwjfW0]

CodePudding user response:

int count=0;
While (the count & lt; 11) {
System. The out. Println (RandomStringUtils. Random (6));
+ + count;
}
  • Related