i have this code for generate unique_code
using Random Package
import random
FullChar = 'CDHKPMQRVXY123456789'
total = 20
count = 7
for i in range(total):
select = random.sample(FullChar, count)
random.shuffle(select)
unique_code = ''.join(select)
print(entries)
I Tried Using Secrets Package
import random
FullChar = 'CDHKPMQRVXY123456789'
total = 20
count = 7
for i in range(total):
select = random.sample(FullChar, count)
select = secrets.SystemRandom.sample(FullChar, count)
secrets.SystemRandom.shuffle(select)
unique_code = ''.join(select)
Here I use random package to generate unique_code(import random), but I think this is the old way to generate unique_code with this package, I want to use secrets package to generate unique_code(import secrets). What is the best way to use a secret package(import secrets), if previously I used a random package to generate unique_code like the code I wrote earlier?
When I used Random Package it's Clear, but when i changes it to secret package it's showing error
select = secrets.SystemRandom.sample(FullChar, count)
TypeError: sample() missing 1 required positional argument: 'k'
Thanks
Aucun commentaire:
Enregistrer un commentaire