I'd ask exactly what kind of "problems" are you having. Compile time? Runtime? Code throws an exception or doesn't run correctly?
A little more detail would help, because the code you posted here won't even compile for me.
Also confusing for me is what you're using the StringBuffer for. You load it with a random set of characters from array, but then you don't use it again.
You are performing operations on array, and those won't affect sb at all, even if they would work. Rethink your logic, then update your code accordingly.