最近在论坛看到有人问,如何快速生成100万不重复的8位编号,对于这个问题,有几点是需要注意的: 1. 如何生成8位随机数,生成的数越随机,重复的可能性当然越小 2. 控制不重复 3. 考虑性能 针对这个问题,我写了如下的示例来解决,希望能为有这类需求的人提供指导 */ USE tempdb GO --创建测试表 CREATE TABLE tb(id char(8)) --创建用于自动过滤重复值的唯一索引 CREATE UNIQUE INDEX IX_tb ON tb(id) W
''' 随机发送n位数字+字母的验证码 ''' import random def get_verified(length): code = '' for i in range(length): num = str(random.randint(0, 9)) ALP = chr(random.randint(65, 90)) alp = chr(random.randint(97, 122)) res = random.choice((num, ALP, alp)) code += res re
Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible. Note: The length of num is less than 10002 and will be ≥ k. The given num does not contain any leading zero. Ex