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
0
votes
4 answers

I have some problems with a coin toss program

I am pretty new to java and using codehs, i need to find the amount and percentage of heads/ tails in a 100 toss program. I've got the 100 flips down but the percentage and printing the amount are beyond me, here is my code and thanks for the…
0
votes
2 answers

How to program an unfair or biased coin flip in Ruby?

I need to make a coin flip that obeys a certain probability of outcome. For example, a coin flip with a 67% chance of coming out Heads, 83% chance of coming out Tails, etc. I managed to get the result I'm after by populating an array with 100 true…
San Diago
  • 992
  • 1
  • 11
  • 25
0
votes
3 answers

Solution to converting int to string in my "Coin Flip" Game?

Just trying to make a coin flip game, but also trying to make the coin which equals a random number 0 or 1 to convert to a string type "heads" or "tails". New to programming so please don't judge if it seems amateurish. Thank you. namespace…
Rom
  • 53
  • 1
  • 3
0
votes
2 answers

Small probabilities in Python

How accurate is Python's random() function? Assume I'd like to make a decision based on a 1 / 234276901 probability coin flip, can I still use a if random() < 1. / 234276901: statement? How accurate would such statement be? (in terms of the actual…
R B
  • 541
  • 9
  • 23
0
votes
2 answers

Calculating observed values from a coin-toss simulation in R

I have a dataframe which was compiled by running a simulation on a two-coin toss 1000 times. I.e. there is two-coins thrown in each test. The test is repeated 1000 times. Heads are 1, tail are 2. Here is a preview of the dataframe. X1 …
user3200293
  • 153
  • 3
  • 18
0
votes
1 answer

Assigning values to a matrix in R

I could not find a solution to this in stack exchange. I have the following example matrix (showing only the first 8 values) that show the sum of 20 fair coin flips (heads=1, tails=0). print(Flips) [,1] [1,] 16 [2,] 11 [3,] 8 [4,] …
Adam
  • 173
  • 2
  • 10
0
votes
3 answers

Array inside a for loop, inside a forloop - throwing ArrayIndexOutOfBoundsException

I want to flip 5 coins as a group - 1024 times and count how many tails i get. However i am getting ArrayIndexOutOfBoundsException: 4 error. Is this because j in the second loop is not reset when the first loop runs its first time? If so, how would…
heatl0rd
  • 1
  • 2
0
votes
1 answer

Need help tossing a coin in Java

I am struggling creating my java coin toss for my webpage. I need to write a Java script to put on the webpage that will show pictures of coins being tossed and carry out the coin toss. here is what I have, why isn't it working? It just opens a new…
0
votes
2 answers

python define a variable in an if statement

I want to make a coin toss / dice roll in python but i cannot figure out how to define / change a variable inside an if statement. import random def roll(number): if(number==1): {print("Take a moment to think that through")} …
ei1
  • 161
  • 2
  • 3
  • 9
0
votes
1 answer

Python 2.7 Coin Flip Program Crashes Every Time

I'm having this strange problem with a simple coin flip program where, instead of giving me some sort of error, whenever i run this code it just sort of crashes. I type in a yes or no answer and hit enter, but it does nothing. Then I hit enter again…
0
votes
2 answers

Why does remove(x) not work?

I've tried to make a simple function, that tosses coin n times, fifty (50) times in this example, and then stores the results to the list 'my_list'. Tosses are thrown using the for loop. If the result of the tosses are not 25 heads and 25 tails (i.e…
Kasperi Koski
  • 55
  • 1
  • 1
  • 12
0
votes
7 answers

Why are my if statements not working consistently?

I'm making a coin toss program for my c++ class and we are required to make a function that flips a coin and prints out if it is heads or tails, and print 10 per line. When I ran the program though the if statements I used to detect if the coin was…
user3427139
  • 17
  • 2
  • 5
0
votes
3 answers

coin flip program problems, C programming

This is my program for making a coin flip simulator, this is for school so I have to use my own code. But I need help the idea is to multiply the variable coin by 3.3 and then rounding off the decimals checking if its odd or even and associating…
Hopelessdecoy
  • 85
  • 1
  • 8
0
votes
2 answers

flip coin 100 times get exactly 50 Matlab

If I flip a coin 100 times, what is the probability that exactly 50 will be heads? My thoughts were to get the number of times exactly 50 appeared in the 100 coin flips out of 1000 times and divide that by 1000, the number of events. I have to model…
azumakazuma
  • 63
  • 10
0
votes
2 answers

longest sequence of consecutive heads or tails in coinFlip

This program is supposed to simulate 200 coin flips and print out the length of the longest sequence of heads or tails. Hey guys, I'm new at programming. I'm stuck in the middle of writing this. Can someone help me to understand the logic behind…