java生成4位随机数工具类代码,可用于发送验证码
import java.util.Random;
public class GetRandom {
public static String getFourRandom(){
Random random = new Random();
String fourRandom = random.nextInt(10000) + "";
int randLength = fourRandom.length();
if(randLength<4){
for(int i=1; i<=4-randLength; i++)
fourRandom = "0" + fourRandom ;
}
return fourRandom;
}
}