# 使用 JS 如何生成一个随机字符串
更多描述
random
接收一个整数作为随机数的个数,最多生成 8 个随机数
// 'a839ac'
random(6);
// '8abc'
random(4);
Issue
欢迎在 Gtihub Issue 中回答此问题: Issue 637 (opens new window)
Author
const random = (n) =>
Math.random()
.toString(36)
.slice(2, 2 + n);
random();
// => "c1gdm2"
random();
// => "oir5pp"