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.

141 questions
36
votes
7 answers

How do I simulate flip of biased coin?

In unbiased coin flip H or T occurs 50% of times. But I want to simulate coin which gives H with probability 'p' and T with probability '(1-p)'. something like this: def flip(p): '''this function return H with probability p''' # do something …
Pratik Deoghare
  • 35,497
  • 30
  • 100
  • 146
7
votes
11 answers

Python code for the coin toss issues

I've been writing a program in python that simulates 100 coin tosses and gives the total number of tosses. The problem is that I also want to print the total number of heads and tails. Here's my code: import random tries = 0 while tries < 100: …
Ru1138
  • 163
  • 1
  • 2
  • 12
7
votes
3 answers

Coin flip simulation never exceeding a streak of 15 heads

I was working on a simulation of the St Petersburg Paradox when I realized my coin-flipping code never recorded any streaks of greater than 15 heads in a row. I ran the simulation 100,000,000 times, which should have resulted in an average of 1526…
tpixel
  • 97
  • 6
4
votes
1 answer

3D Coin Flipping Animation on SKSpriteNode

I'm currently developing a game using Swift 3 and SpriteKit. I have a coin that falls during a game that the user can collect. Right now, it falls and doesn't have any rotation or anything. I want to add a 3D spinning effect while it falls. This…
Nik
  • 1,664
  • 2
  • 14
  • 27
4
votes
4 answers

Count number of alternations in a coin flip sequence

I have a sequence of ones and zeros and I would like to count the number of alternations, e.g: x <- rbinom(10, 1, 1/2) > x [1] 0 0 1 1 1 1 1 0 1 0 Thus I would like to count (in R) how many times the sequence alternates (or flips) from one to…
Frank Zafka
  • 829
  • 9
  • 30
4
votes
2 answers

Coin flip program

I tried making a program that flips a coin(shows image of heads first and later shows image of tails) and I encountered problems trying to have the image of the coin viewed when I ran the problem; only a blank screen would show. I don't know…
user1629075
  • 109
  • 1
  • 3
  • 11
4
votes
3 answers

Simulate coin toss for one week?

This is not homework. I am interested in setting up a simulation of a coin toss in R. I would like to run the simulation for a week. Is there a function in R that will allow me to start and stop the simulation over a time period such as a week? If…
Frank Zafka
  • 829
  • 9
  • 30
3
votes
3 answers

Nested loops with C++ coin toss

I have to write a program that runs a loop for a coin toss. I am supported to enter a number into the console and have it run a loop of the coin toss for that many times. I need to use nested loops. I have been working on this for hours and cannot…
David
  • 389
  • 5
  • 22
3
votes
11 answers

Automate the boring stuff - Coin flip streaks

I know there's tons of questions about it by now, even for the same problem, but I think I tried a bit of a different approach. The task is to to 10.000 samples of 100 flips each and then compute the probability of a 6x heads or tails streak over…
mr_harm
  • 61
  • 1
  • 1
  • 6
3
votes
4 answers

Flip a coin problem

I have been playing around and wrote this little piece of code. I am trying to flip a coin defined number of times and then count how many tails and heads I am getting. So here it is: private void Start_Click(object sender, EventArgs e) { int…
HelpNeeder
  • 6,383
  • 24
  • 91
  • 155
3
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
  • 53
  • 1
  • 5
3
votes
4 answers

Tossing a fair coin for 100 times and count the number of heads. Repeat this simulation 10**5 times

Write a program to simulate tossing a fair coin for 100 times and count the number of heads. Repeat this simulation 10**5 times to obtain a distribution of the head count. I wrote below code to count number of heads 100 times, and outer loop should…
Hashmatullah Noorzai
  • 771
  • 3
  • 12
  • 34
3
votes
3 answers

Random Number Generator / Coin Flip / A-B Generator - Run Until X in a Row in R

I am trying to generate random results, such as from a coin flip. I'd like to run this A/B or heads/tails generator until I get x of the same result consecutively. I found this code online for a coin flip: sample.space <- c(0,1) theta <- 0.5 # this…
2
votes
1 answer

Comparing multiple coin flip experiments. 1 Experiment = 100 Flips. Trying to simulate 10 experiments

import random as rd n = 0 ListOfStreaks = [] ListOfResults = [] while n != 10: numberOfStreaks = 0 for i in range(100): Flip = rd.randint(0,1) ListOfResults.append(Flip) for i in range(96): count = 0 for…
Trey
  • 21
  • 3
2
votes
1 answer

Generating random uniform random numbers from coin flip algorithm tends to generate more 0s than expected

I am trying to generate random numbers in the range from 0 to 99 using a function rcoin that returns 0 or 1 with equal probability. I have written the following code that converts a binary number generated from successive calls of rcoin function,…
1
2 3
9 10