← 返回首页

随机字符串生成教程

常见随机码类型

类型格式位数安全性
PIN码纯数字4-6位
验证码纯数字4-6位
邀请码字母+数字6-8位
订单号日期+随机16-24位
API Token全字符集32-64位很高

订单号设计方案

  1. 时间戳 + 自增序号:20260322143025 + 000001
  2. 前缀 + 时间戳 + 随机数:ORD + 20260322 + 143025 + 0001
  3. UUID:550e8400-e29b-41d4-a716-446655440000
  4. 雪花算法:时间戳 + 机器ID + 序列号(19位数字)

安全注意事项

JavaScript安全随机数

// 安全随机数(推荐)
const arr = new Uint32Array(1);
crypto.getRandomValues(arr); // 0 ~ 2^32-1

// 生成安全随机字符串
function secureRandom(len) {
  const chars = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789';
  const arr = new Uint32Array(len);
  crypto.getRandomValues(arr);
  return Array.from(arr, n => chars[n % chars.length]).join('');
}

在线随机字符串生成器

使用我们的随机字符串生成器,自定义字符集和长度,一键生成订单号、验证码、邀请码。