import java.util.Random;
//class coinToss
class coinToss extends Thread
{
public void run()
{
//variable declaration and initialization
int toss, tail=0, head=0;
Random rand = new Random();
for(int i=0; i<1000; i++)
{
//assign random number 0 or 1
toss = rand.nextInt(2);
//we assume that if random number is 1 then it is head otherwise
tail
if(toss == 1)
{
head++;
}
else
{
tail++;
}
}
//display the frequency of head
System.out.println("Frequency of heads: " + head);
//display the frequency of tail
System.out.println("Frequency of tails: " + tail);
}
}
//main class
public class Main
{
public static void main(String[] args)
{
coinToss toss = new
coinToss();
//method calling
toss.start();
}
}
OUTPUT:
java language question: Write a thread that tosses a coin 1000 times and computes the frequency...
Using c++ Write a function named coinToss that simulates tossing a coin. When you call the function it should generate and return a random number in the range 1 through 2. 1 represents heads and 2 represents tails. Exercise 1 (40 points) Write a function named coinToss that simulates tossing a coin. When you call the function it should generate and return a random number in the range 1 through 2.1 represents heads and 2 represents tails Use the function...
Problem: Write a function named coinToss that simulates the tossing of a coin. When you call the function, it should generate a random number in the range of 1 through 2. If the random number is 1, the function should display “heads.” If the random number is 2, the function should display “tails.” Demonstrate the function in a program that asks the user how many times the coin should be tossed and then simulates the tossing of the coin that...
One application of an absolute value inequality is the concept of the unfair coin. If a coin is tossed 100 times, we would expect approximately 50 of the tosses to be heads; however this is rarely the case.1. Toss a coin 100 times to test this hypothesis. Record the number of times the coin is heads and the number of times the coin is tails on the lines below. You may want to ask someone to tally the results of...
If I toss a fair coin 20 times and all 20 tosses result in tails (or “T”), the probability of heads (or "H") appearing on the 21st coin toss is less than 0.5 but greater than 0. 0.5. O 1. O greater than 0.5 but less than 1.
Write a program where 3 separate threads simulate flipping a coin. The 3 threads should execute concurrently and each thread should do 1000 flips. Keep track of what is currently the record number of consecutive heads/tails (separately) and which thread produced that sequence. Every time a thread produces a longer sequence, display a message on the screen. Make sure other threads can’t interfere when updating the current record. N.B: This is a java object oriented program assignment.
# JAVA Problem Toss Simulator Create a coin toss simulation program. The simulation program should toss coin randomly and track the count of heads or tails. You need to write a program that can perform following operations: a. Toss a coin randomly. b. Track the count of heads or tails. c. Display the results. Design and Test Let's decide what classes, methods and variables will be required in this task and their significance: Write a class called Coin. The Coin...
A biased coin is tossed n times. The probability of heads is p and the probability of tails is q and p=2q. Choose all correct statements. This is an example of a Bernoulli trial n-n-1-1-(k-1) p'q =np(p + q)n-1 = np f n- 150, then EX), the expected value of X, is 100 where X is the number of heads in n coin tosses. f the function X is defined to be the number of heads in n coin tosses,...
Write a C++ program that simulates coin tossing. For each toss of the coin the program should print Heads or Tails. The program should toss a coin 100 times. Count the number of times each side of the coin appears and print the results at the end of the 100 tosses. The program should have the following functions as a minimum: void toss() - called from main() and will randomly toss the coin and set a variable equal to the...
1. A coin is flipped 200 times. Use the Binom.dist function to determine the probability that there are between 39 and 103(inclusive) heads flipped. 2. Use Rand() to generate 1000 random numbers from 0-1 and then use Binom.inv to show the number of heads in flipping a coin 200 times for each of the random numbers.Next prove the average number of heads from the 1000 is close to 100. Use the average function with the results of the Binom.inv.
#1 A coin will be tossed 10 times. Find the chance that there will be exactly 2 heads among the first 5 tosses, and exactly 4 heads among the last 5 tosses. #2 An 11-digit number is randomly chosen by drawing 11 times from a box that has one ticket for each of the numbers 0 to 9 and writing down the numbers on the tickets in the order in which they are drawn. Find the chance that exactly 4...