Without knowing about you particular use case, what are these codes used for, it’s hard to give a definitive answer. You could look at one way hashing, the openssl library is available on most platforms and provides sha3 secure one way hashes.
If a raw hash is too much data you could use an agreed subset of the hash, say you want a 6 character code take characters 1,2,3,5,8,13 say each time. This does increase the risk of collision, two values giving the same code.
The advantage of this approach is that you don’t have to store the codes, they can always be regenerated.
But a lot of this depends on volumes and what your planning to actually do!