For newly created labels, assign a random style

I have created 6 css classes for tags: tag-style-1, tag-style-2, tag-style-3, tag-style-4, tag-style-5, tag-style-6. I want to randomly assign one of the above 6 classes to a new tag when I create a new tag, so that the newly created tag will have a different style. I know the tag style component is possible, but it needs to be added manually, not randomly assigned!

Not exactly random, and not at tag creation, but you can do something similar to the Tag Icons component and use the replaceTagRenderer() from the plugin-api to modify the html of the tags at view (see discourse-tag-icons/common/header.html at master · isabella232/discourse-tag-icons · GitHub).

A function like this would take the tag name, map the tag name to a number 1-6 (i.e. encode the string into base 6 and take the last digit/apply modulo), and add it to the HTML string. It wont be random since the style would be determined by tag name, but it would keep the style the same for all users

The original default render tag function is here: