# Random font for multiple fields, code clean-up help

**URL:** <https://forums.ankiweb.net/t/random-font-for-multiple-fields-code-clean-up-help/8458>\
**Category:** Card Design\
**Created:** [March 18, 2021, 12:44pm UTC](https://forums.ankiweb.net/t/random-font-for-multiple-fields-code-clean-up-help/8458 "2021-03-18T12:44:29Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![yaoberh](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/yaoberh/32/7505_2.png) [@yaoberh](https://forums.ankiweb.net/u/yaoberh)\
**Post date:** [March 18, 2021, 12:44pm UTC](https://forums.ankiweb.net/t/random-font-for-multiple-fields-code-clean-up-help/8458/1 "2021-03-18T12:44:29Z")

</div>

Hey all, I’ve been adding different snippets of code to my card design and ended up with a lot of different randomizers. Everything is random, font, color, size, position, background. The font is randomized with an extension which invokes QFontDatabase and associates it to a \< class \>. The rest is all code which I obtained over months of testing. The thing is the code is very inefficient and sometimes doesn’t work correctly. In fact, I want to make the code work for multiple fields but it isn’t. If anyone can help me with this, I’m linking the pastebin with the full code so nothing gets lost here. The extension I’m using for random fonts is this one: 1603486068

The main three fields which need to be randomized are Expression, Simplified and Traditional.  
I made three addons so the QFontDatabase fetches three different font sets and associates them to three different classes being that Expression is a Japanese field and the others are Traditional and Simplified Chinese respectively (QFontDatabase.Japanese, etc).

I’m not a coding expert and I don’t know how to reorganize the parts so they work correctly.  
The code: [random all anki - Pastebin.com](https://pastebin.com/XsBf5ABL)

If anyone’s willing to help poor me to make this work I’ll make an honorable effigy in my memory to them haha  
Thanks!

---

_[View the full topic](https://forums.ankiweb.net/t/random-font-for-multiple-fields-code-clean-up-help/8458)._
