genanki
genanki copied to clipboard
Generate model ID based on hash of its parameters
@kerrickstaley and I explain why it would not be wise to do so in https://github.com/kerrickstaley/genanki/issues/49#issuecomment-698996326. Basically it would mean that one cannot update the model without generating obsolete models in user databases.
Hello,
Thank you for this awesome and simple library.
Would it be wise for the user to generate a model id and deck id with the hash of a string hardcoded in the program?
I generated 12 decks using the same model of cards. For the model I used id hash(hardcodeddate+hardcodedprojectname+'model') % (1 << 31) and for each deck I used id hash(hardcodeddate+hardcodedprojectname+deckname) % (1 << 31).
This somewhat contradicts your advice to use random numbers, but not too much. Is that OK or is there some counter-argument?
The return value of hash() for a given input changes across runs of your program. So no, that isn’t a good approach because the deck ID will change every time you run the program. You could consider using a SHA256 hash though.
Thank you for the quick response! I'm using hashlib.sha256 now.