coin-flipping

Coin tossing and generating graphs

半城伤御伤魂 提交于 2021-02-11 14:11:23
问题 Could someone generate those graphs or at least help me with that ? I want to generate that probability of getting heads and tails in a undetermined number of flips. Actually its not like that but consider pthetaGivenData like this and check my code. Probably you´ll know what I want to get. This is what I´ve done so far: The while wasnt working. I couldnt store my results of each coin result in add, so then, pthetaGivenData in storage as well. I was trying to generate the first five data

Coin tossing and generating graphs

坚强是说给别人听的谎言 提交于 2021-02-11 14:10:51
问题 Could someone generate those graphs or at least help me with that ? I want to generate that probability of getting heads and tails in a undetermined number of flips. Actually its not like that but consider pthetaGivenData like this and check my code. Probably you´ll know what I want to get. This is what I´ve done so far: The while wasnt working. I couldnt store my results of each coin result in add, so then, pthetaGivenData in storage as well. I was trying to generate the first five data

JavaScript: How To Code a Heads/Tails With Specific Probability Chance Percentage?

£可爱£侵袭症+ 提交于 2021-02-05 12:18:50
问题 I've implemented the function: function coinFlip() { return(Math.floor(Math.random()*2) === 0) ? 'Heads' : 'Tails'; } And it's all working fine (I already tested it). My problem is, how do I make this function so that the probability of getting 'Heads' is 30% while the probability of getting 'Tails' is 70%? Thanks in advance 回答1: function coinFlip() { return(Math.random() < 0.3) ? 'Heads' : 'Tails'; } 回答2: If one of three toss coin is head it doesn't mean that in 10 toss, there will be 3

Append rle result from loop

别来无恙 提交于 2019-12-14 03:24:22
问题 I am running a coin-toss simulation with a loop which runs about 1 million times. Each time I run the loop I wish to retain the table output from the RLE command. Unfortunately a simple append does not seem to be appropriate. Each time I run the loop I get a slightly different amount of data which seems to be one of the sticking points. This code gives an idea of what I am doing: N <- 5 #Number of times to run rlex <-NULL #begin loop############################# for (i in 1:N) { #tells R to

Simulate coin toss for one week?

五迷三道 提交于 2019-12-10 16:34:45
问题 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 all goes well, I may want to increase the length of the simulation period. For example: x <- rbinom(10, 1, 1/2) So to clarify, instead of 10 in the code above, how do I keep the simulation going for a week (number of trials in a week versus set

Python code for the coin toss issues

≡放荡痞女 提交于 2019-12-10 13:39:03
问题 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: tries += 1 coin = random.randint(1, 2) if coin == 1: print('Heads') if coin == 2: print ('Tails') total = tries print(total) I've been racking my brain for a solution and so far I have nothing. Is there any way to get the number of heads and tails

Iteration performance

萝らか妹 提交于 2019-12-08 03:33:14
问题 I made a function to evaluate the following problem experimentally, taken from a A Primer for the Mathematics of Financial Engineering. Problem : Let X be the number of times you must flip a fair coin until it lands heads. What are E[X] (expected value) and var(X) (variance)? Following the textbook solution, the following code yields the correct answer: from sympy import * k = symbols('k') Expected_Value = summation(k/2**k, (k, 1, oo)) # Both solutions work Variance = summation(k**2/2**k, (k,

Iteration performance

℡╲_俬逩灬. 提交于 2019-12-07 08:35:31
I made a function to evaluate the following problem experimentally, taken from a A Primer for the Mathematics of Financial Engineering . Problem : Let X be the number of times you must flip a fair coin until it lands heads. What are E[X] (expected value) and var(X) (variance)? Following the textbook solution, the following code yields the correct answer: from sympy import * k = symbols('k') Expected_Value = summation(k/2**k, (k, 1, oo)) # Both solutions work Variance = summation(k**2/2**k, (k, 1, oo)) - Expected_Value**2 To validate this answer, I decided to have a go at making a function to