In the last article I posted the C++ Code for a simple Bean Machine output. Now I did the same in Powershell. I know this is not really a fantastic Powershell script, but its good to show others how things get done in Powershell.
Like in the C++ bean machine it works like this:
And the Output should look like this:
And here is how you do this in Powershell:
#Config [int]$ballCount = 100 [array]$box = @(0, 1, 2, 3, 4, 5) [string]$line = " +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-->" [string]$numbers = " 0 5 10 15 20 25 30 35 40 45 50" [object]$random = New-Object System.Random #count for([int]$i = 0; $i -lt $ballCount; $i++){ [int]$counter = 0 for([int]$j = 0; $j -lt 5; $j++){ $leftorright = $random.next(0,2) $counter = $counter + $leftorright } $box[$counter] = $box[$counter] + 1 } #Output Write-Host $numbers Write-Host $line for ([int]$t = 0; $t -lt 6; $t++){ [string]$Statusline = "" for ([int]$u = 0; $u -lt $box[$t]; $u++){ [string]$Statusline += "#" } Write-Host $t "|" $Statusline $box[$t] Write-Host $line }
Thank you, needed this script for collage. Again Thank you so much.
Hahaha, shit ben niet de enige… hszuyd ofnie… ;)