2 Star 1 Fork 0

huaxiahonker/手机号码生成

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
code.py 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
huaxiahonker 提交于 2023-06-27 06:33 . add code.py.
import random
def generate_mobile_numbers(count):
prefixes = {
"中国电信": ["133", "153", "180", "181", "189", "177", "173", "149", "199"],
"中国联通": ["130", "131", "132", "155", "156", "185", "186", "145", "175", "176", "166"],
"中国移动": ["134", "135", "136", "137", "138", "139", "147", "150", "151", "152", "157", "158", "159", "172", "178", "182", "183", "184", "187", "188", "198"],
}
mobile_numbers = set()
while len(mobile_numbers) < count:
operator = random.choice(list(prefixes.keys()))
prefix = random.choice(prefixes[operator])
suffix = "".join(random.choice("0123456789") for _ in range(8))
mobile_number = prefix + suffix
mobile_numbers.add((operator, mobile_number))
return mobile_numbers
# 生成1000个不重复手机号码示例并保存到文件
mobile_numbers = generate_mobile_numbers(5000000)
with open("mobile_numbers.txt", "w") as file:
for operator, mobile_number in mobile_numbers:
# file.write(f"运营商:{operator}\n")
file.write(f"{mobile_number}\n")
# file.write("---\n")
print("手机号码已保存到mobile_numbers.txt文件中。")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/huaxiahonker/mobile-number-generation.git
git@gitee.com:huaxiahonker/mobile-number-generation.git
huaxiahonker
mobile-number-generation
手机号码生成
master

搜索帮助