#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int main()
{
int i, j, ansChoice, selectedChoice, knownWrongChoice, oldSelectedChoice;
int result[2]={ 0 };
//plant a seed
srand( time(NULL) );
for( j = 0 ; j < 10 ; j++ )
{
result[0] = result [1] = 0;
for ( i = 0; i < 100000 ; i++ )
{
do
{
//random right choice
ansChoice = rand() % 4;
// now give a selected choice
selectedChoice = rand() % 4;
//let think of some wrong choice
do{
knownWrongChoice = rand() % 4;
}while( knownWrongChoice == ansChoice );
//if selected choice is known to be wrong, don't count this question
}while( knownWrongChoice == selectedChoice );
//if we confirm that choice.
if( selectedChoice == ansChoice)
result[0]++;
//if we change random new selected choice.
oldSelectedChoice = selectedChoice;
do{
selectedChoice = rand() % 4;
}while( selectedChoice == knownWrongChoice || oldSelectedChoice == selectedChoice );
//collect result
if( selectedChoice == ansChoice)
result[1]++;
}
//print
printf("\n%d\nnochange = %d (%.2f) \nchange = %d (%.2f)\n from %d times",j,
result[0] , ((float)result[0]/i)*100 ,
result[1] , ((float)result[1]/i)*100 , i );
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHRpbWUuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgppbnQgbWFpbigpCnsKCWludCBpLCBqLCBhbnNDaG9pY2UsIHNlbGVjdGVkQ2hvaWNlLCBrbm93bldyb25nQ2hvaWNlLCBvbGRTZWxlY3RlZENob2ljZTsKCWludCByZXN1bHRbMl09eyAwIH07CgkKCS8vcGxhbnQgYSBzZWVkCglzcmFuZCggdGltZShOVUxMKSApOwoJZm9yKCBqID0gMCA7IGogPCAxMCA7IGorKyApCgl7CgkJcmVzdWx0WzBdID0gcmVzdWx0IFsxXSA9IDA7CgkJZm9yICggaSA9IDA7IGkgPCAxMDAwMDAgOyBpKysgKQoJCXsKCQkJZG8KCQkJewoJCQkJLy9yYW5kb20gcmlnaHQgY2hvaWNlCgkJCQlh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