我想随机生成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.
答案 0 :(得分:1)
创建字符串var“0123456789ABCDEF0123456789ABCDEF”,然后使用随机生成器混合字符和chek的顺序(如果不是两次),最后一步将其剪切为12个字符。