flip-a-coin | A coin flip simulator using WebGL | Game Engine library
kandi X-RAY | flip-a-coin Summary
kandi X-RAY | flip-a-coin Summary
This is a simple coin flip simulation using WebGL and basic game design techniques. The aim of this project is for me to learn the basics of WebGL and to implement a basic game engine from scratch.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of flip-a-coin
flip-a-coin Key Features
flip-a-coin Examples and Code Snippets
Community Discussions
Trending Discussions on flip-a-coin
QUESTION
So I have A
and B
play a game which begins with A
tossing a coin. If it shows head, A
wins and game over. Else, B
tosses and if B
gets a head, B
wins and game over. Basically, the game continues until whoever's coin shows a head first.
Theoretically, the probability of A
winning is 2/3
, and the probability of B
winning is 1/3
. Referenced here
I'm trying to simulate this in Python
, running 4000
simulations. However, I'm not really getting close to 2/3
for A
and 1/3
for B
. Below is my code:
ANSWER
Answered 2019-Mar-07 at 00:37Your Awin
and Bwin
computations say that if A wins on the 5th toss, then since A tossed 3 times and B tossed 2 times, A gets 3/5 of a win and B gets 2/5. This is not how victory is supposed to work.
Also, you want random.randrange
, not random.randint
, and your placement of the Atoss
and Btoss
initialization before the loop instead of inside the loop means they don't reset on a new iteration. (The toss counts are unnecessary in a correct implementation, though.)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install flip-a-coin
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page