Function Repository Resource:

CoinTossSimulator

Source Notebook

Dynamically simulate tossing a coin

Contributed by: Wolfram|Alpha Math Team

ResourceFunction["CoinTossSimulator"][]

creates an interface for dynamically simulating coin tosses.

ResourceFunction["CoinTossSimulator"][w]

uses probability w of getting "heads".

Details and Options

ResourceFunction["CoinTossSimulator"] returns a DynamicModule expression.
The returned interface includes the buttons Flip, Report and Ideal results. These simulate a coin toss and use CellPrint to display a report of the current results and a plot comparing the results to ideal results, respectively.

Examples

Basic Examples (1) 

Simulate tossing a fair coin:

In[1]:=
ResourceFunction["CoinTossSimulator"][]
Out[1]=

Scope (2) 

Simulate an unfair coin:

In[2]:=
ResourceFunction["CoinTossSimulator"][1/3]
Out[2]=

Clicking the "Report" button returns a summary of the simulation statistics:

In[3]:=
ResourceFunction["CoinTossSimulator"][1/3]
Out[3]=
Out[3]=

Properties and Relations (1) 

The information returned by the "Ideal results" button is also available via the resource function IdealCoinTossStatistics:

In[4]:=
ResourceFunction["CoinTossSimulator"][]
Out[4]=
Out[4]=
In[5]:=
ResourceFunction["IdealCoinTossStatistics"][5, 3]
Out[5]=

Publisher

Wolfram|Alpha Math Team

Version History

  • 2.0.0 – 23 March 2023
  • 1.0.0 – 18 September 2020

Related Resources

Author Notes

To view the full source code for CoinTossSimulator, run the following code:

In[1]:=
FileNameJoin[
  ReplacePart[
   FileNameSplit[FindFile["ResourceFunctionHelpers`"]], -1 -> "CoinToss.wl"]] // SystemOpen

License Information