Updated with newer answer and better test
Let\'s say I have the number 382 which is 101111110.
How could I randomly turn a bit which is not 0 to
int changeBit(int a) { a = ~a; int temp = a; while(temp == a) { r = Math.pow(2,(int)(32*random.next())); a = a || r; } return ~a; }