I have no idea how. All I know is that all CIAs have one, and if 2 match, it will cause some problems.
Not exactly:
All titles, including game cards, have one;
and there won't be any "problems", just because installing a cia with the same titleid of another one will remove the other
(a "unique id" is a part of the "title id", to be exact, ????????-?
???????. The console always works with the full title id; however, only the unique id can be "freely" changed, as the other parts have a specific meaning to the system)
To change it in an already made cia, make up a 5-digit hex number between 300 and F7FFF (practically speaking, don't go lower than 2000 as official games are there, also check out the homebrew app titleids here on gbatemp, and the devapp list in my signature), then start reading from there:
https://gbatemp.net/threads/change-unique-id-on-3ds-or-cia.418324/page-2#post-6544473 