1. ## Probabilty Question

I need to Generate 1000 random numbers between 0 and 1. I got this part.
Next i need to identify the probabilty of having a head or a tail if i flipped a coin.
Also i dentify the probabibilty of a side of a six faced die.

I need [to use random numbers\
Code:
```#include <stdio.h>
#include<stdlib.h>

int main()
{
float sum=0, average;
int i;
for (i=0; i<1000; i++) sum=sum;

for (i=0 ;i<1000; i++)
printf("%f\n", 1.0*rand()/RAND_MAX);
printf("\nMAX = %d\n" , RAND_MAX);

printf("The probability for having a Heads or Tails is:\n");
printf ("----                -----\n");
printf("   %d                  %d\n");

return 0;
}```

2. The probability is 1 in 2, and 1 in 6. I'm not sure what you really need to compute here.

Quzah.

3. as quzah said, the probability is 1/2 and 1/6, for your two problems respectively. therefore you dont have to calculate "the probability".

what you probably need to do is an experiment, and determine "the probability of [...] in n = 1000 trials". so, for the coin "experiment", you flip the coin (generate a (pseudo)random number with 2 possible values) and keep track of how many times it turns out heads ("value 1") and how many times it turns out tails ("value 2"). then simply calculate the percentage of each, from the total of 1000 tries. do a similar thing for the next "experiment".

in the case of only two values, you only actually have to keep track of 1 of the values. for example, if, out of 1000 tests, there were 100 tails, you obviously know how many heads there must have been (EDIT: recall that since 1 = P + Q, Q = 1 - P). similarly, for the other experiment, you only need to track 5 of the 6 totals, but im sure just keeping track of all of them isnt a big deal.

after you are finished, you might find it interesting that when you increase the number of tests run for either experiment, they become closer and closer to the "actual" probabilities. try n = 1, 1000, 1000000, etc.

as quzah said, the probability is 1/2 and 1/6, for your two problems respectively. therefore you dont have to calculate "the probability".

what you probably need to do is an experiment, and determine "the probability of [...] in n = 1000 trials". so, for the coin "experiment", you flip the coin (generate a (pseudo)random number with 2 possible values) and keep track of how many times it turns out heads ("value 1") and how many times it turns out tails ("value 2"). then simply calculate the percentage of each value, out of the total of 1000 tries. do a similar thing for the next "experiment".

in the case of only two values, you only actually have to keep track of 1 of the values. for example, if, out of 1000 tests, there were 100 tails, you obviously know how many heads there must have been. similarly, for the other experiment, you only need to track 5 of the 6 totals, but im sure just keeping track of all of them isnt a big deal.

after you are finished, you might find it interesting that when you increase the number of tests run for either experiment, they become closer and closer to the "actual" probabilities. try n = 1, 1000, 1000000, etc.

Yeah i see what you mean . I know i have to write a program that tells me out of 100 flips how many heads and tails i get.Any Suggestions?

5. you mean 1000. and i already gave you my (i thought) detailed suggestion. expand on your code further or write some pseudocode to solve the problem, and we can help you translate it to code. otherwise, just post your code after youve expanded it and let us know the specific problem.

6. Code:
```if heads
else
tails++```
The same sort of thing (though I'd just use an array) for your dice sides.

Quzah.

7. ## I figured out the first part

I figured out the first part of the question any help with the second part?

Code:
```
#include <stdio.h>
#include <time.h>

int flip( );
int main( void )
{

int i;
int tails = 0;

srand(time(NULL));

for ( i= 1; i<= 1000; i++ ){
printf( "%d\n", flip( ));

if (flip( ) == 0)
else
tails++;

}
printf("-----------------\n");
return 0;

}
int flip( )
{
int i = rand() % 2;
if (i == 0)
return 0;
else
return 1;
}```

8. Is it the probability math that you're stuck on?

that's just the

number of times the coin was heads / number of times the coin was flipped.

So if you fliped it 100 times, and got heads 52, your probability would be:

52/100 = .52

And since percent means hundredths, that's 52%

For rolling dice, it's the same thing.

Number of rolled 3's / number of times the die was rolled, or

17/100 = .17, or 17%