In general, if you want to avoid having two different values mapped to one and the same value, then you'd use a loop that terminates only when both values have different values.
So, in randd() you return a random letter, but this one may be the same in each call.
What you could do is to add a loop in your first for()-loop (line 14), that checks whether the current, random letter is already contained in str, and act accordingly.
1 2 3 4
for(int i=0; i < 25; ++i) {
// I've commented the pseudo-code out for now ...
// you might want to think about it yourself. It's not too hard.
}