In my other post with the subject frequency? , the result comes out to be 52 for heads and 48 for tails. It means that it is not 100% randomized result. If had been correctly randomized the result should have been 50 for heads and 50 for tails, know what I mean? How can I achieve perfect randomness in this case?
here is the code which I posted and later corrected.
Quote:
Code:#include<iostream> /* include header files */
#include<conio.h> /* */
#include<iomanip> /* */
using std::cout;
using std::cin;
using std::endl;
using std::setw;
void flip(); // prototype
int main()
{
flip(); // function call
}
void flip(void)
{
int frequency1=0; // declare & initialize frequency1 to 0
int frequency2=0; // declare & initialize frequency2 to 0
int face; // declare face
for(int toss=1; toss<=100; toss++) // coin tossed 100 times
{
face=1+rand()%2; // generate randomly 1 | 2
switch(face) // switch face
{
case 1:
++frequency1; // increment heads
break;
case 2:
++frequency2; // increment tails
break;
default:
cout<< "It should never get here:"; // default should never occur
break; // optional
} // exit switch
} // exit for loop
cout<< setw(10) << "Face" << setw(13) << "Frequency" << endl; // display results
cout<< setw(10) << "Heads" << setw(13) << frequency1 << endl;
cout<< setw(10) << "Tails" << setw(13) << frequency2 << endl;
}