This Python code will generate the required 4-character (Unique_code) serial numbers:

#!/usr/bin/python3
import re

for i in range(1,10000):
    if (i < 1000):
       print ("i =", str(i).zfill(4))
    else:
       m = re.findall(r'(\d)(\d\d\d)', str(i))
       code = 64+int(m[0][0])
       print ("i =",i, "Unique_code =", chr(code) + m[0][1])

Excerpts from output:

i = 0001
i = 0002
...
i = 0999
i = 1000 Unique_code = A000
i = 1001 Unique_code = A001
i = 1002 Unique_code = A002
...
i = 1997 Unique_code = A997
i = 1998 Unique_code = A998
i = 1999 Unique_code = A999
i = 2000 Unique_code = B000
i = 2001 Unique_code = B001
i = 2002 Unique_code = B002
i = 2003 Unique_code = B003
...
i = 9997 Unique_code = I997
i = 9998 Unique_code = I998
i = 9999 Unique_code = I999
Answer from LeadingEdger on Stack Overflow
Starred by 8 users
Forked by 3 users
Languages: Python
🌐
Pythonmana
pythonmana.com › 2021 › 12 › 20211204013240229h.html
Solving the problem of generating serial number in Python
December 4, 2021 - Please answer me Use random Library generation 20 Different software serial numbers . example K56TM-SAKMB-ZN987-PIASZ-JSL96 Generate such a serial number ... import randomstr='ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'for j in range(20): serial='' for i in range(25): index=random.randint(0,len(str)-1) serial=serial+str[index:index+1] if i%5==4 and i<20: serial=serial+'-' print(serial) ... import randoma = []b = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'for i in range(20): a.append('-'.join([''.join([random.choice(b) for x in range(5)]) for n in range(5)]))print('\n'.join(a)) ... 11.8-11.14 [Python learning of college students] community summary + roll call praise of excellent community members & CSDN customized T-shirt reward~
🌐
YouTube
youtube.com › codinggpt
python serial number generator - YouTube
Download this code from https://codegive.com Creating a Python Serial Number Generator TutorialIn this tutorial, we'll walk through the process of creating a...
Published: December 13, 2023
Views: 112
🌐
Program Creek
programcreek.com › python
Python get serial number
def GetSerialNumber(self): # serial number format: # Hex Register Values: 30 30 30 37 37 32 32 39 38 37 -> High part of each byte = 3, low part is SN # decode as s/n 0007722987 # at present I am guessing that the 3 that is interleaved in this data is the line of gensets (air cooled may be 03?) if self.PreNexus: return "Unknown" RegStr = "x" % MODEL_REG Value = self.GetRegisterValueFromList(RegStr) # Serial Number Register if len(Value) != 20: return "" if Value[0] == 'f' and Value[1] == 'f': if self.SerialNumberReplacement != None: return self.SerialNumberReplacement # this occurs if the cont
🌐
Parasoft Forums
forums.parasoft.com › soatest
Serial Number Generator — Parasoft Forums
December 8, 2008 - It'll just create-or-rename a directory ./MySoaTestFilename.serialNumber.1 (for persistence) and return the next number ... Sounds easy enough. I really appreciate you volunteering your thoughts. iouBeer++ Cheers. Keith. ... If you're only concerned about generating positive integers, whereas the value of the integer doesn't matter, then I would recommend to simply grab the current time in milliseconds (e.g. System.currentTimeMillis() returns the current time in long ms - FYI, our python scripting is really Jython which is a hybrid of Java and Python, this means you can use Java objects in your python/jython script).
Find elsewhere
🌐
YouTube
youtube.com › coding lovers
How Generate Specific Length Serial Number Using Python - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new features · © 2024 Google LLC
Published: March 17, 2021
Views: 1K
🌐
PyPI
pypi.org › project › serialbox
serialbox · PyPI
SerialBox solves the non-trivial problem of generating and distributing serial number information from system to system for the use in manufacturing and supply chain environments.
      » pip install serialbox
    
Published: Mar 10, 2024
Version: 3.0.9
🌐
Python.org
discuss.python.org › python help
How to make series number - Python Help - Discussions on Python.org
February 18, 2022 - can someone help me? How to Write a function to generate the following series of numbers:[4,3,8,6,16,12,….,192] Thanks
🌐
PyPI
pypi.org › project › PySerialNumbers
PySerialNumbers · PyPI
Usually python on a Windows system and python3 on a GNU/Linux system. You can find the documentation on https://pyserialnumbers.readthedocs.io/en/latest/. This example shows how to create a list of 20 serial numbers from SN01 to SN20 according a string defining this list.
      » pip install PySerialNumbers
    
Published: May 05, 2025
Version: 1.0.1
🌐
GitHub
gist.github.com › angeloped › 3febaaf71ac083bc2cd5d99d775921d0
Python code to get motherboard serial number. For Linux, MacOS, and Windows. · GitHub
if "darwin" in os_type: command = "ioreg -l | grep IOPlatformSerialNumber" elif "win" in os_type: command = "wmic bios get serialnumber" elif "linux" in os_type: command = "hal-get-property --udi /org/freedesktop/" \ "Hal/devices/computer --key system.hardware.uuid" return os.popen(command).read().replace("\n", "").replace(" ", "").replace(" ", "") ... We can do it the other way around by using dmidecode -s baseboard-serial-number for newer Linux variants:
🌐
LabEx
labex.io › tutorials › python-soldier-serial-number-generator-302764
Soldier Serial Number Generator - Unique ID Creation | LabEx
The generated ID should be a string of 8 hexadecimal characters. The __iter__() method should return the WeaponFactory instance itself, so that the class can be used as an iterator.
🌐
GitHub
github.com › ertyseidohl › namegenerator
GitHub - ertyseidohl/namegenerator: Python Serial-Number to Name Generator
Something like "002133" A serial number will always return the same name (given the same seed, noun file, and adjective file) -e <number> --end <number> The serial number with which to end.
Author: ertyseidohl
🌐
PyPI
pypi.org › project › serial-generator
serial-generator · PyPI
A simple module to generate random serial numbers.
      » pip install serial-generator
    
Version: 0.1.0
🌐
GitHub
github.com › topics › serial-number
serial-number · GitHub Topics · GitHub
You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. ... A Python script to extract the serial number of a remote Fortinet device. ... lightweight security laravel plugins laravel-framework laravel-package license unique-id randomizer serial-number serial-numbers php-native serial-number-generator php-serial-number sn-generator
Top answer
1 of 2
1

The expression `range(1, 5)' creates a list of numbers from 1 to 4. So in your first test, you're asking whether the first character in your serial number is equal to that list:

"1" == [1, 2, 3, 4]

Probably not...

What you probably want to know is whether a digit is in the range (i.e. from 1 to 5, I assume, not 1 to 4).

Your other hurdle is that the first character of the serial is a string, not an integer, so you would want to take the int() of the first character. But that will raise an exception if it's not a digit. So you must first test to make sure it's a digit:

if serial_list[0].isdigit() and int(serial_list[0]) in range(1, 6):

Don't worry, if it's not a digit, Python won't even try to evaluate the part after and. This is called short-circuiting.

However, I would not recommend doing it this way. Instead, simply check to make sure it is at least "1" and no more than "5", like this:

if "1" <= serial_list <= "5":

You can do the same thing with each of your tests, varying only what you're checking.

Also, you don't need to convert the serial number to a list. serial_check is a string and accessing strings by index is perfectly acceptable.

And finally, there's this pattern going on in your code:

if thing == other:
   pass
elif thing != other:
   (do something)

First, because the conditions you are testing are logical opposites, you don't need elif thing != other -- you can just say else, which means "whatever wasn't matched by any if condition."

if thing == other:
   pass
else:
   (do something)

But if you're just going to pass when the condition is met, why not just test the opposite condition to begin with? You clearly know how to write it 'cause you were putting it in the elif. Put it right in the if instead!

if thing != other:
    (do something)

Yes, each of your if statements can easily be cut in half. In the example I gave you for checking the character range, probably the easiest way to do it is using not:

if not ("1" <= serial_list <= "5"):
2 of 2
0

Regarding your python, I'm guessing that when your wrote this:

if serial_list[0] == range(1,5):

You probably meant this:

if 1 <= serial_list[0] <= 5:

And when you wrote this:

if serial_list[1] == random.choice('ABCDEF'):

You probably meant this:

if serial_list[1] in 'ABCDEF':

There are various other problems with your code, but I'm sure you'll improve it as you learn python.

At a higher level, you seem to be trying to build something like a software activation code generator/validator. You should know that just generating a string of pseudo-random characters and later checking that each is in range is an extremely weak form of validation. If you want to prevent forgeries, I would suggest learning about HMAC (if you're validating on a secure server) or public key cryptography (if you're validating on a user's computer) and incorporating that into your design. There are libraries available for python that can handle either approach.

🌐
Drupal
drupal.org › project › 3097544 › issues › 3097549
Create a basic setup of serial number generator module [#3097549] | Drupal.org
December 23, 2019 - What can I do to help? I have a project right now that needs to generate serial numbers for licenses. -- My project will watermark files based on the serial number. I can write specifications, test and do minor programming in C or Python.
🌐
Stack Overflow
stackoverflow.com › questions › 61048641 › python-to-add-serial-number-in-a-text-file-and-header
Python : to add serial number in a text file and header - Stack Overflow
April 6, 2020 - What did you expect to happen instead? Any errors? If you don't know where to start coding, do a web search and read some tutorials first. Good luck! ... data = """ 123456789 1234 test123 124555669 6547 test456 564984565 58475 test789 """ header = "Sr.no. MD5 Size Path\n" output = header + "\n".join( "{}\t{}".format(line_number, line) for line_number, line in enumerate( (item for item in data.split("\n") if item), 1)) print(output)