total[20000]; unsigned int same_count = 0; unsigned int now_same = 9; unsigned int same_count_result[6] = {0}; for (int i = 0; i < 20000; i++) { rdrand(&rand); total[i] = rand & 0b1; } for (int i = 0; i < 20000; i++) { if (total[i] == now_same) { same_count++; } else { now_same = total[i]; if (0 < same_count && same_count < 6) { same_count_result[same_count - 1]++; } else if (same_count > 5) { same_count_result[5]++; } same_count = 0; } } for (int i = 0; i < 6; i++) { printf("%d\n", same_count_result[i]); }