I have the next code:
t= (int)(Math.random()*8+1)+96; //ascii table
if (t!= 96){
choose[(int)(t-97)] = 1;
r[0] = (char)t;}
}
I try that in r[0], there would be only characters from b to h ('a' is not allow). When I run it, I see that sometimes r[0] contains 'a'. What can be the reason?
‘a’ is ASCII 97, and you’re not preventing that.
Why don’t you just pick a value from 98 (‘b’) to 104 (‘h’) in the first place, instead of allowing ‘a’ to be picked and then rejecting it?
(I’d also suggest using
Random.nextIntinstead ofMath.random, and character literals instead of magic numbers, but…)