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
30
votes
7 answers

How do I simulate flip of biased coin in python?

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
  • 30,271
  • 27
  • 94
  • 143
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
  • 151
  • 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
  • 75
  • 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,634
  • 2
  • 10
  • 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
  • 799
  • 8
  • 29
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
  • 799
  • 8
  • 29
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
  • 339
  • 4
  • 17
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…
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
8 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
  • 37
  • 1
  • 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,…
2
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
  • 5,933
  • 21
  • 80
  • 141
2
votes
1 answer

Simulating 10,000 Coinflips in Python Very Slow

I am writing a simulation that creates 10,000 periods of 25 sets, with each set consisting of 48 coin tosses. Something in this code is making it run very slowly. It has been running for at least 20 minutes and it is still working. A similar…
mks212
  • 773
  • 1
  • 15
  • 35
2
votes
1 answer

php loop flip coin until 2 heads, then stop

I'm new to php and am trying to write a loop that will flip a coin until exactly two heads have been flipped and then stop. So far I've written a function for coin flipping: function cointoss () { $cointoss = mt_rand(0,1); $headsimg = '
pzstein
  • 35
  • 3
1
2 3 4 5 6 7 8