如何随机生成重复不超过 2 位数字的 12 位十六进制



我想随机生成 12 位十六进制。约束是不再重复 2 位数字作为整体,并且没有连续重复。如何编写高效的代码?

xx11xxxxxxxx is not valid because the same digit (e.g., 1) appears consecutively.
12121xxxxxxx is not valid as well because the digit 1 appears thrice.

创建字符串 var "0123456789ABCDEF0123456789ABCDEF",然后使用随机生成器混合字符和 chek 的顺序(如果不是两次),最后一步将其切割为 12 个字符。

最新更新