微信小程式生成隨機驗證碼

2021-08-26 14:40:48 字數 743 閱讀 5237

wxml檔案}

js檔案

data: {

code:"獲取驗證碼"

getcode:function(){

this.createcode();

createcode() {

var code;

//首先預設code為空字串

code = '';

//設定長度,這裡看需求,我這裡設定了4

var codelength = 4;

//設定隨機字元

var random = new array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');

//迴圈codelength 我設定的4就是迴圈4次

for (var i = 0; i < codelength; i++) {

//設定隨機數範圍,這設定為0 ~ 36

var index = math.floor(math.random() * 36);

//字串拼接 將每次隨機的字元 進行拼接

code += random[index];

//將拼接好的字串賦值給展示的code

this.setdata({

code: code

驗證碼隨機生成

pip install captcha驗證碼隨機生成 python 版本 3.6 captcha 版本 0.3 from captcha.image import imagecaptcha import numpy as np import matplotlib.pyplot as plt from...

隨機生成驗證碼

coding utf 8 created on mon sep 16 01 21 02 2019 author administrator import random from captcha.image import imagecaptcha import numpy as np from pil...

隨機生成驗證碼

private static int r private static int g private static int b private static stringbuffer buffer public static final char chars public static random ...