-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom.cmd
More file actions
126 lines (112 loc) · 2.98 KB
/
Random.cmd
File metadata and controls
126 lines (112 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@echo off
rem =====
rem For more information on ScriptTiger and more ScriptTiger scripts visit the following URL:
rem https://scripttiger.github.io/
rem Or visit the following URL for the latest information on this ScriptTiger script:
rem https://github.com/ScriptTiger/Randomness
rem =====
rem The %random% variable will give you 15 random bits (32767 total, 1,2,4,..,16384)
rem For 32 bits of random (positve and negative):
rem set /a "(%random%<<30)+(%random%<<15)+%random%"
rem For 31 bits of random (positive only):
rem set /a "(%random%<<16)+(%random%<<1)+(%random%&1)"
rem Accept command-line arguments
if not "%~1"=="" goto %1
rem Interactive menu
:choice
echo 1] Toss a coin
echo 2] Roll some dice
echo 3] Pick a number
echo 4] Rock, paper, scissors
echo 5] Random Generator
echo X] Exit
choice /c 12345x /n
cls
goto %errorlevel%
rem Toss a coin
:1
set /a toss="%random%&1"
if %toss%==1 (set toss=heads) else (set toss=tails)
echo The coin lands on %toss%!
if not "%~1"=="" exit /b
goto choice
rem Roll X-sided die Y times
:2
if "%1"=="" (
set /p dice=Number of rolls?
set /p sides=Number of sides?
) else (
set dice=%2
set sides=%3
)
set rolls=0
setlocal ENABLEDELAYEDEXPANSION
for /l %%0 in (1,1,%dice%) do (
for /l %%a in (1,1,%sides%) do set /a side_%%a="(!random!<<30)+(!random!<<15)+!random!"
call :sort side roll
echo Roll %%0 is !roll!.
set /a rolls=!rolls!+!roll!
)
echo Total rolled is !rolls!.
for /l %%0 in (1,1,%sides%) do set side_%%0=
endlocal
if not "%~1"=="" exit /b
goto choice
rem Pick a number from X to Y
:3
if "%1"=="" (
set /p start=What number should your range start at?
set /p end=What number should your range end at?
) else (
set start=%2
set end=%3
)
setlocal ENABLEDELAYEDEXPANSION
for /l %%0 in (%start%,1,%end%) do set /a num_%%0="(!random!<<30)+(!random!<<15)+!random!"
call :sort num num
echo The number picked between %start% and %end% is %num%^^!
for /l %%0 in (%start%,1,%end%) do set num_%%0=
endlocal
if not "%~1"=="" exit /b
goto choice
rem Rock, paper, scissors
:4
setlocal ENABLEDELAYEDEXPANSION
for %%0 in (rps_Rock rps_Paper rps_Scissors) do set /a %%0="(!random!<<30)+(!random!<<15)+!random!"
call :sort rps rps
echo %rps%^^^!
for %%0 in (rps_Rock rps_Paper rps_Scissors) do set %%0=
endlocal
if not "%~1"=="" exit /b
goto choice
rem Matrix
:5
setlocal ENABLEDELAYEDEXPANSION
if "%1"=="" (
echo 1] 0 through 9
echo 2] Only 1 and 0
echo X] Exit
choice /c 12x /n
set choice=!errorlevel!
) else (
set choice=%2
)
cls
if %choice%==1 endlocal&cmd /v:on /c"for /l %%0 in () do @set /a !random!"
if %choice%==2 endlocal&cmd /v:on /c"for /l %%0 in () do @set /a !random!^&1"
endlocal
if not "%~1"=="" exit /b
goto choice
rem Exit
:6
exit /b
rem Sort a variable set and return the bottom value
:sort
for /f "tokens=2" %%0 in (
'^(
for /f "tokens=2,3 delims=_=" %%a in ^(
^'set %1_^'
^) do @echo %%b %%a
^) ^| sort'
) do set %2=%%0
exit /b