Thank you for posting this code. I was going to write similar code to support Charlieplexing using the switch / case statement but I suspect my attempt would have been clumsy.
When using the Charlieplexing library, I do not know how to select a CharlinPin at random, so had to go with not using that library.