Skip to content

Instantly share code, notes, and snippets.

@nicholasjackson827
Created February 14, 2022 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasjackson827/10baee339fbfb69b61dbec45005b3fb6 to your computer and use it in GitHub Desktop.
Save nicholasjackson827/10baee339fbfb69b61dbec45005b3fb6 to your computer and use it in GitHub Desktop.
Magic Gumball Simulation
function Get-StatisticsResults {
$NumberOfQuarters = 10;
$PercentageOfGettingQuarterBack = 0.5;
$NumberOfGumballs = 0;
while ($NumberOfQuarters -ne 0) {
$NumberOfGumballs++;
$RandNumber = (Get-Random -Minimum 0.0 -Maximum 1.0)
if ($RandNumber -lt $PercentageOfGettingQuarterBack) {
$NumberOfQuarters--;
}
}
return $NumberOfGumballs
}
1..10000 |
ForEach-Object { Get-StatisticsResults } |
Group-Object |
Select-Object Name,Count,@{Name="Graph";Expression={"*" * [math]::floor($_.Count / 50)}} |
Sort-Object Name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment