branch | noai |
changeset 9628 | b5c2449616b5 |
parent 9627 | 6a7c8ead2328 |
child 9629 | 66dde6412125 |
9627:6a7c8ead2328 | 9628:b5c2449616b5 |
---|---|
1083 } |
1083 } |
1084 } |
1084 } |
1085 |
1085 |
1086 static int PickRandomBit(uint bits) |
1086 static int PickRandomBit(uint bits) |
1087 { |
1087 { |
1088 uint num = 0; |
|
1089 uint b = bits; |
|
1090 uint i; |
1088 uint i; |
1091 |
1089 uint num = RandomRange(CountBitsSet(bits)); |
1092 do { |
|
1093 if (b & 1) num++; |
|
1094 } while (b >>= 1); |
|
1095 |
|
1096 num = RandomRange(num); |
|
1097 |
1090 |
1098 for (i = 0; !(bits & 1) || (int)--num >= 0; bits >>= 1, i++) {} |
1091 for (i = 0; !(bits & 1) || (int)--num >= 0; bits >>= 1, i++) {} |
1099 return i; |
1092 return i; |
1100 } |
1093 } |
1101 |
1094 |