zoukankan      html  css  js  c++  java
  • 随机车牌算法

    普通燃油车牌一般是“粤A·05976”

    纯电动“粤A·D05976”

    插电混合动力:“粤A·F05976”

    代码如下:

    # !/usr/bin/env python
    # -*- coding:utf-8 -*-
    # Author:Hiuhung Wan
    
    import random
    
    count = 0
    num_of_total = 5
    list0 = []
    # prefix = '粤A·D'   # 纯电动小车
    # prefix = '粤A·F'   # 插电混合动力小车
    prefix = '粤A·'   # 前缀
    
    def shuffle_str(str):        # 随机排序
        list_str = list(str)
        random.shuffle(list_str)
        return ''.join(list_str)
    
    for i in range(50):
        plate_num = ''
        num_of_digi = random.randint(3, 5)              # 3 4 5位
        num_of_letter = num_of_total - num_of_digi      # 2 1 0位
        for j in range(num_of_digi):
            ran_digi = random.randint(0, 9)
            plate_num += str(ran_digi)
        if num_of_letter != 0:                 # 有字母
            for k in range(num_of_letter):
                ran_letter = random.choice('ABCDEFGHJKLMNPQRSTUVWXYZ')  # 没有O与I
                plate_num += str(ran_letter)
        plate_num = shuffle_str(plate_num)
        plate_num = prefix + plate_num   # 加入前缀
        list0.append(plate_num)
    # print(len(list0))
    
    for x in range(len(list0)):
        if (x+1) % 5 == 0:
            print(list0[x])
        else:
            print(list0[x], end=', ')
    

      

    效果如下:

    粤A·417H0, 粤A·16621, 粤A·C4954, 粤A·R7438, 粤A·55151
    粤A·18921, 粤A·10178, 粤A·8528B, 粤A·92C0G, 粤A·60K64
    粤A·55820, 粤A·18728, 粤A·37271, 粤A·FA977, 粤A·9AX91
    粤A·3663X, 粤A·2M14M, 粤A·418NY, 粤A·918GT, 粤A·5K26A
    粤A·51D56, 粤A·24075, 粤A·U0477, 粤A·01D25, 粤A·98227
    粤A·81B79, 粤A·L5972, 粤A·G5853, 粤A·15MR8, 粤A·05976
    粤A·45G4R, 粤A·34617, 粤A·JH612, 粤A·27X1K, 粤A·5YW87
    粤A·Q9172, 粤A·44397, 粤A·V697U, 粤A·06443, 粤A·5E771
    粤A·97R29, 粤A·59314, 粤A·12K19, 粤A·7935W, 粤A·59684
    粤A·0835C, 粤A·15105, 粤A·72269, 粤A·78980, 粤A·C65Q7
    

      

  • 相关阅读:
    异构数据库同步工具调研
    ubuntu16.04 Golang语言开发环境搭建
    串口USB单一映射及重命名
    linux arm 交叉编译ACE(ubuntu16.04)
    ubuntu16.04 下Mongo数据库搭建
    ubuntu 增加一个用户 并赋予权限
    go 通过http发送图片file内容
    git 简单命令总结
    gitlab ssh_key
    ubuntu16.04 程序开机自启动设置及启动优化
  • 原文地址:https://www.cnblogs.com/hiuhungwan/p/10497134.html
Copyright © 2011-2022 走看看