In a fair coin we have an equal chance (50%) of either getting a head' or tail'. That is if we toss the coin a large number of times we would observe head approximately 50% of the time. Write a program to implement a biased coin toss where the chance of getting a head is 70% (and tail 30%). That is if we invoke the program 1000 times we should see the head randomly approximately 700 times.
Answers
Answered by
0
Hi am happy I will be home in this day tomorrow I am have
Answered by
0
The python code for doing the required task is as follows:
from pylab import*
def cointoss(n):
rv=random.random(0,1,size=n)
for i in rv:
if (rv[i]<=0.7):
rv[i]='heads'
else:
rv[i]='tails'
return rv
- The following code uses a random variable generator which gives us n random numbers between 0 to 1 .
- Making the coin biased is equivalent to making the random numbers less than 0.7 equal to heads and the rest equal to tails.
- If n is set to 1000 and the function cointoss is called , it will print an array containg 1000 heads and tails , where number of tails will be almost equal to 700.
Similar questions
English,
6 months ago
Hindi,
6 months ago
Science,
6 months ago
Computer Science,
1 year ago
Political Science,
1 year ago
Math,
1 year ago