Introduction: Batch File Heads or Tails Generator
Code for a random heads or tails generator.
- Open notepad
- Copy code below
- Save it as ht.bat and click TEXT DOCUMENT and change it to ALL FILES
- Click save
@echo off
:top
cls
echo To flip the coin press enter
set /p enter=
set /a a=%random% %% 2+1
if %a% EQU 1 (
echo Heads pause goto top
)else echo Tails pause goto top
2 Discussions
5 years ago
I have made a new version of this for every one. Copy and paste this code:
@echo off
cls
:loop
cls
set /a a = 0
set /a b = 0
:game
cls
set /p ht= Press enter to flip the coin.
echo KACHING!!!
pause
set /a th = %random% %% 2+1
if %th% == 1 (
goto c
)else if %th% ==2 (
goto d
)else goto game
:c
cls
echo HEADS
echo.
echo -------------------
echo.
set /a a = %a% + 1
echo Heads: %a%
echo Tails: %b%
pause
goto game
:d
cls
echo TAILS
echo.
echo --------------------
echo.
set /a b = %b% + 1
echo Heads: %a%
echo Tails: %b%
pause
goto game
5 years ago
Nice way to make a decision.