![]() |
Unique Random ID on Table - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Unique Random ID on Table (/thread-18758.html) |
Unique Random ID on Table - talius - May-30-2019 Hi all, I'm new using Python and need help from you. I use pycharm to write code. I need to generate an unique Random ID for each transaction i create using the following table: My table contains: Date Name Address Code --> It will be alphanumeric (between 5 to 7 length with may be special characters) Transaction type.. Could you please assist to make it simple? Thanks T RE: Unique Random ID on Table - ichabod801 - May-30-2019 What have you tried? We're not big on writing code for people here, but we would be happy to help you fix your code when you run into problems. When you do run into problems, please post your code in Python tags, and clearly explain the problem you are having, including the full text of any errors. I will say that this is easy to do with a for loop and random.choice. RE: Unique Random ID on Table - michalmonday - May-30-2019 from random import choice from string import ascii_letters, punctuation, digits def get_code(): return ''.join(choice(char_set) for _ in range(code_length)) code_length = 5 char_set = ascii_letters + punctuation + digits possible_codes = len(char_set) ** code_length print('Number of possible codes =', possible_codes) print() print('Sample:\n') for i in range(15): print(get_code())
|