dimanche 13 août 2023

how to generate a unique code without twin characters next to each other in python?

thank you for helping me whoever it is..

Here's my code

import random

FullChar = 'ABCDEFGHJKLMNPQRTUVWXY123456789'
total = 1000
counts = 8
count = int(counts)
entries = []

while (0 < 1) :
    for i in range(total):
        unique_code = ''.join(random.choice(FullChar) for j in range(count)) 
        entry = (unique_code)
        entries.append(entry)
    
    print(entries)
    entries.clear()

I want to generate a unique code using python, but with the condition that there can't be the same characters side by side and there can only be a maximum of 3 of the same digits, here I use python 3 with the random.choice method

Expected Unique Code

WHQUFUN0
ABABABUF
CN1EL1X1
H2HJEKAK

Unique code that's not allowed

WHQUUFN0
RXBBBHLW
CN1EL11B
E0CCFF9N



Aucun commentaire:

Enregistrer un commentaire