Questions tagged [coin-flipping]

Coin flipping is the process of programmatically simulating a coin flip, that is randomly picking a choice among two possibilities.

Coin flipping is the process of programmatically simulating a coin flip, that is randomly picking a choice among two possibilities.

118 questions
2
votes
3 answers

Coin Flip Simulation

I just started to learn Python and am trying to code the following question: Coin Flip Simulation- Write some code that simulates flipping a single coin however many times the user decides. The code should record the outcomes and count the number of…
Danqi Liu
  • 43
  • 1
  • 5
2
votes
1 answer

How do I write a function that prints counts of values in an array, taking the array as a parameter?

Starting with the below program that creates an array of coin flips, I have to add a function that prints out the total number of heads and total number of tails flipped. The function must take the array of flips as a parameter. This is the given…
J..
  • 35
  • 1
  • 5
2
votes
2 answers

Dealing with normal (Gaussian) distribution

I basically stucked on rather simple problem: Toss N coins and discover, how many of them land heads Solution performance must not depend on N, so we can't just call Math.random() < 0.5 N times. Obviously, there is Gaussian distribution to the…
augur
  • 201
  • 1
  • 10
2
votes
1 answer

coin flip experiment in C++ using std::rand() giving incorrect result

I'm trying to count the number of occurrences of the string HHHHHHTTTTTT in 1 million flips. For the coin flip, I'm using a simple std::rand() % 2. The code below. Mathematically, the expected answer is (10^6 - 12 + 1) / 2^12 = 244 I got this result…
xdavidliu
  • 1,198
  • 6
  • 23
2
votes
0 answers

Unbiase coin toss using the C++11 random library

I have a program that needs to generate very many 0/1 random values. Because this is needed many times and in different part of the code, I wish to have a time efficient and easy to use random generator to perform this task. I started using the…
Prolix
  • 294
  • 1
  • 12
2
votes
1 answer

2 Player Coin Flipping

I'm trying to create a Java program that flips two coins to see who wins the coin flip. It prompts the user for a number of coin flips. If the first player has heads and the second player has tails, then it should output “Player 1 Wins!” and vice…
user1762387
  • 31
  • 1
  • 5
1
vote
9 answers

Do you have a better idea to simulate coin flip?

Right now i have return 'Heads' if Math.random() < 0.5 Is there a better way to do this? Thanks edit: please ignore the return value and "better" means exact 50-50 probability.
unj2
  • 47,759
  • 80
  • 235
  • 362
1
vote
2 answers

Function to output probability in PHP

I'm trying to find a function that takes a number and outputs the expected results as follows: if input=1 then output should be Array{'0','1'} if input=2 then output should be Array{'00','01','10','11'} if input=3 then output should be…
Songo
  • 5,195
  • 7
  • 51
  • 88
1
vote
1 answer

Generate data from a coin flipping experiment

I have a coin and the coin has memory. i.e. the last flip impacts the probability of heads on this flip. How do I write code to generate data from this process? Specifically, from this process, I want to be able to generate n=1000 data points. P(H |…
Gingerbread
  • 1,478
  • 6
  • 18
  • 28
1
vote
1 answer

Interpretation of the coin toss code in C

During classes the teacher presented the C code for simulation of the coin toss. I know that there have been answered many questions about this topic, however, none of them relates strictly to my problem. #include #include…
Question
  • 53
  • 7
1
vote
3 answers

How to return all combinations of N coin flips using recursion?

Request: Using JavaScript, write a function that takes an integer. The integer represents the number of times a coin is flipped. Using recursive strategies only, return an array containing all possible combinations of coin flips. Use "H" to…
cj102
  • 13
  • 2
1
vote
1 answer

How does modulo work when simulating a coin toss in c++?

#include #include #include int main() { // Create a number that's 0 or 1 srand (time(NULL)); int coin = rand() % 3; // If number is 0: Heads // If it is not 0: Tails if (coin == 0) { …
Juan
  • 73
  • 4
1
vote
1 answer

Code to count times to get all heads or all tails is returning only times to get heads

I am pretty happy to say I think I have my first coin flip problem running. I am counting how many times it takes to get all heads or all tails in a trial of 7 flips. In theory it should take around 64 times to get either all heads or all…
1
vote
0 answers

Modelling three biased coins from generated data

Here is an experiment I ran to better understand pymc3. I have three biased coins and I perform the below experiment: 1. Toss Coin1. If head choose Coin2 else choose Coin3 2. Randomly choose a number n (between 1 and 10) that implies coin tosses to…
1
vote
2 answers

These Directions Are Not Clear To Me

I have to make a program that uses two files called coin. One file named coin and the other named coin tester. The directions in the book are confusing to me, but I still tried to do the assignment. Here are the directions that were given: Create…
Lucas Kopp
  • 11
  • 2