20位以内数字随机数生成

perfect start 5月前 ⋅ 490 阅读

java实现

public static String buildVerifyCode(int length) {
		String code = Math.round(Math.random() * Math.pow(10, length) + Math.pow(10, length - 1))  + "";
		code = code.length() > length ? code.substring(0, length) : code;
		return code;
	}

js实现


function buildVerifyCode(length) {
    let code = Math.round(Math.random() * Math.pow(10, length) + Math.pow(10, length - 1));

    code = code.length > length ? code.substr(0, length) : code;
    return code;
}

全部评论: 0

    我有话说: