Excel或Python生成随机字符串

Excel:

随机小写字母:=CHAR(INT(RAND()*25+97))
随机大写字母:=CHAR(INT(RAND()*25+65))
随机数字:=CHAR(INT(RAND()*9+48))
随机数字大小写字母:IF(INT(RAND()*2)=0,CHAR(INT(RAND()*9+48)),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*25+65)),CHAR(INT(RAND()*25+97))))
混合6位:=CONCATENATE(IF(INT(RAND()*2)=0,CHAR(INT(RAND()*9+48)),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*25+65)),CHAR(INT(RAND()*25+97)))),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*9+48)),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*25+65)),CHAR(INT(RAND()*25+97)))),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*9+48)),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*25+65)),CHAR(INT(RAND()*25+97)))),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*9+48)),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*25+65)),CHAR(INT(RAND()*25+97)))),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*9+48)),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*25+65)),CHAR(INT(RAND()*25+97)))),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*9+48)),IF(INT(RAND()*2)=0,CHAR(INT(RAND()*25+65)),CHAR(INT(RAND()*25+97)))))

 

Python:

''.join(random.sample('abcdefghijklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789', length))

作者: hqiang1984

量化自我,极简主义