目标
生成密码学随机的 v4 UUID 并逐行打印;数量参数经钳制防止误传巨数拖垮终端。
要点
isV4 用正则校验版本位为 4、变体位为 8/9/a/b;唯一性测试一次生成 200 个断言集合大小仍为 200。
提示
版本与变体位是 v4 的结构特征,随机碰撞在位模式下不可能出现。
验证
node –test 验证形状与唯一性;CLI 传参 3 打印三行 36 字符 UUID。 复现命令:
node --test uuid.test.mjs
node uuid.mjs 3
预期输出要点:Running with the argument 3 prints three lines, each a 36-character UUID with version 4 and variant bits set.
实测证据:Node 22.23.2: node –test -> 2 passed; CLI printed 3 unique v4 UUIDs, each matching the version and variant regex.