How to generate random data in a batch file?

April 4, 2011 at 10:17:10
Specs: Windows XP
I would like to practice for my guitar using a batch file. So, if I want a batch file to generate data from (A, A#, B, C, C#, D, D#, E, F, F#, G, G#), is it possible?

See More: How to generate random data in a batch file?

Report •


#1
April 4, 2011 at 11:18:10
I'm sure there is a prettier more efficient way of doing this... but give this a try:


@echo off
:repeat
cls
Echo Randomizing Note - Please Wait...
set number=%random%
if %number% LEQ 12 goto finish
goto repeat
:finish
cls
If %number% EQU 1 Echo Please Play A
If %number% EQU 2 Echo Please Play A#
If %number% EQU 3 Echo Please Play B
If %number% EQU 4 Echo Please Play C
If %number% EQU 5 Echo Please Play C#
If %number% EQU 6 Echo Please Play D
If %number% EQU 7 Echo Please Play D#
If %number% EQU 8 Echo Please Play E
If %number% EQU 9 Echo Please Play F
If %number% EQU 10 Echo Please Play F#
If %number% EQU 11 Echo Please Play G
If %number% EQU 12 Echo Please Play G#
Echo.
Echo Press any key to generate a new note
pause >nul
goto repeat


Report •

#2
April 4, 2011 at 11:51:12
It worked, I used the help of another tutorial on the website to make it more efficient.
@echo off
cls
:1
Echo Randomizing Note - Please Wait...
set /a number=%random%%%12+1
If %number% EQU 1 Echo Please Play A
If %number% EQU 2 Echo Please Play A#
If %number% EQU 3 Echo Please Play B
If %number% EQU 4 Echo Please Play C
If %number% EQU 5 Echo Please Play C#
If %number% EQU 6 Echo Please Play D
If %number% EQU 7 Echo Please Play D#
If %number% EQU 8 Echo Please Play E
If %number% EQU 9 Echo Please Play F
If %number% EQU 10 Echo Please Play F#
If %number% EQU 11 Echo Please Play G
If %number% EQU 12 Echo Please Play G#
pause >nul
goto 1

Report •

#3
April 4, 2011 at 12:23:13
I have one more question. If I wish for the batch file to automatically generate a random note, is it possible? (Without me having to press a key) Thanks for your help!

Report •

Related Solutions

#4
April 4, 2011 at 12:37:26
*generate a random note after specified amount of time

Report •

#5
April 4, 2011 at 13:13:55
Sour music. Random chords followed by random notes.

Report •

#6
April 4, 2011 at 17:03:07
Thanks for following up (and teaching me something new in the process ;) )
--
Sure, you can use ping to create a "wait" to your code. In the example below I added a 5 second wait. 1000 Milliseconds = 1 Second



@echo off
:1
cls
Echo Randomizing Note - Please Wait...
set /a number=%random%%%12+1
If %number% EQU 1 Echo Please Play A
If %number% EQU 2 Echo Please Play A#
If %number% EQU 3 Echo Please Play B
If %number% EQU 4 Echo Please Play C
If %number% EQU 5 Echo Please Play C#
If %number% EQU 6 Echo Please Play D
If %number% EQU 7 Echo Please Play D#
If %number% EQU 8 Echo Please Play E
If %number% EQU 9 Echo Please Play F
If %number% EQU 10 Echo Please Play F#
If %number% EQU 11 Echo Please Play G
If %number% EQU 12 Echo Please Play G#
ping 10.10.10.10 -n 1 -w 5000 >nul
goto 1


Report •

#7
April 5, 2011 at 08:07:52
If you would like to see the final programme...
Thanks for your help. I found out that ping is not accurate enough so I downloaded the windows 2003 resource kit to use the sleep command. Bye

@echo off
Title Rejjy's Fretboard Trainer
cls
ECHO Hello and welcome to Fretboard training program 1.0.1.
ECHO This will generate a random note for you to play on, along with a specified string so that you can
ECHO map the whole fretboard in your brain.
ECHO Please use this with a metronome on low BPM. Also make sure your guitar is well tuned.
ECHO You can generate a random note after a specified time duration or upon pressing a button.
ECHO You can now enter the number and tuning of strings you would like to practice on.
ECHO Made by Rejjy of Hill 3 (www.facebook.com/Hill3.Band)

:begin
echo.
set b=0
set /p x=Please enter the number of strings you would like to pratice on (1 to 8)
if "%x%"=="" goto enter
set /a k=%x%*12
set /a b=%x%*1
If %b% GTR 8 goto 6
If %x% EQU 0 goto 6
If NOT "%b%"=="%x%" (ECHO ERROR : Invalid choice.) ELSE goto str1
goto begin

:6
echo You have not entered the number of strings within the range. Please re-enter within a range of 1-8.
goto begin

:Enter
Echo ERROR : Invalid choice.
goto begin

:str1
set /p s1=Enter the tuning of the first string -
If %x% EQU 1 goto 42 ELSE goto str2
:str2
set /p s2=Enter the tuning of the second string -
If %x% EQU 2 goto 42 ELSE goto str3
:str3
set /p s3=Enter the tuning of the third string -
If %x% EQU 3 goto 42 ELSE goto str4
:str4
set /p s4=Enter the tuning of the fourth string -
If %x% EQU 4 goto 42 ELSE goto str5
:str5
set /p s5=Enter the tuning of the fifth string -
If %x% EQU 5 goto 42 ELSE goto str6
:str6
set /p s6=Enter the tuning of the sixth string -
If %x% EQU 6 goto 42 ELSE goto str7
:str7
set /p s7=Enter the tuning of the seventh string -
If %x% EQU 7 goto 42 ELSE goto str8
:str8
set /p s8=Enter the tuning of the eighth string -


:42
echo.
Echo Would you like to -
Echo a) Automatically generate a random note after a specified amount of time?
Echo b) Generate a random note upon pressing a key?
set /p j=Please enter A or B as per your choice.
if "%j%"=="" goto enter2
if %j%==a goto Input_time
if %j%==A goto Input_time
if %j%==b goto Auto
if %j%==B goto Auto
echo ERROR : Invalid choice
goto 42

:Enter2
Echo ERROR : Invalid choice.
goto 42

:Input_time
echo.
set z=0
ECHO Please enter the specified amount of time to wait before generating a new note
set /p y=(in ms, 1 s = 1000 ms)
If "%y%"=="" goto yeah
set /a z=%y%*1
If NOT "%z%"=="%y%" (ECHO ERROR : Invalid time duration.) ELSE goto 2
goto Input_time

:yeah
Echo ERROR : Invalid time duration.
Goto Input_time

:2
echo.
goto Post_input

:Post_input
set /a R=%random%%%k%+1
If %R% EQU 1 Echo Please play A on string %s1%
If %R% EQU 2 Echo Please play A# on string %s1%
If %R% EQU 3 Echo Please play B on string %s1%
If %R% EQU 4 Echo Please play C on string %s1%
If %R% EQU 5 Echo Please play C# on string %s1%
If %R% EQU 6 Echo Please play D on string %s1%
If %R% EQU 7 Echo Please play D# on string %s1%
If %R% EQU 8 Echo Please play E on string %s1%
If %R% EQU 9 Echo Please play F on string %s1%
If %R% EQU 10 Echo Please play F# on string %s1%
If %R% EQU 11 Echo Please play G on string %s1%
If %R% EQU 12 Echo Please play G# on string %s1%
If %R% EQU 13 Echo Please play A on string %s2%
If %R% EQU 14 Echo Please play A# on string %s2%
If %R% EQU 15 Echo Please play B on string %s2%
If %R% EQU 16 Echo Please play C on string %s2%
If %R% EQU 17 Echo Please play C# on string %s2%
If %R% EQU 18 Echo Please play D on string %s2%
If %R% EQU 19 Echo Please play D# on string %s2%
If %R% EQU 20 Echo Please play E on string %s2%
If %R% EQU 21 Echo Please play F on string %s2%
If %R% EQU 22 Echo Please play F# on string %s2%
If %R% EQU 23 Echo Please play G on string %s2%
If %R% EQU 24 Echo Please play G# on string %s2%
If %R% EQU 25 Echo Please play A on string %s3%
If %R% EQU 26 Echo Please play A# on string %s3%
If %R% EQU 27 Echo Please play B on string %s3%
If %R% EQU 28 Echo Please play C on string %s3%
If %R% EQU 29 Echo Please play C# on string %s3%
If %R% EQU 30 Echo Please play D on string %s3%
If %R% EQU 31 Echo Please play D# on string %s3%
If %R% EQU 32 Echo Please play E on string %s3%
If %R% EQU 33 Echo Please play F on string %s3%
If %R% EQU 34 Echo Please play F# on string %s3%
If %R% EQU 35 Echo Please play G on string %s3%
If %R% EQU 36 Echo Please play G# on string %s3%
If %R% EQU 37 Echo Please play A on string %s4%
If %R% EQU 38 Echo Please play A# on string %s4%
If %R% EQU 39 Echo Please play B on string %s4%
If %R% EQU 40 Echo Please play C on string %s4%
If %R% EQU 41 Echo Please play C# on string %s4%
If %R% EQU 42 Echo Please play D on string %s4%
If %R% EQU 43 Echo Please play D# on string %s4%
If %R% EQU 44 Echo Please play E on string %s4%
If %R% EQU 45 Echo Please play F on string %s4%
If %R% EQU 46 Echo Please play F# on string %s4%
If %R% EQU 47 Echo Please play G on string %s4%
If %R% EQU 48 Echo Please play G# on string %s4%
If %R% EQU 49 Echo Please play A on string %s5%
If %R% EQU 50 Echo Please play A# on string %s5%
If %R% EQU 51 Echo Please play B on string %s5%
If %R% EQU 52 Echo Please play C on string %s5%
If %R% EQU 53 Echo Please play C# on string %s5%
If %R% EQU 54 Echo Please play D on string %s5%
If %R% EQU 55 Echo Please play D# on string %s5%
If %R% EQU 56 Echo Please play E on string %s5%
If %R% EQU 57 Echo Please play F on string %s5%
If %R% EQU 58 Echo Please play F# on string %s5%
If %R% EQU 59 Echo Please play G on string %s5%
If %R% EQU 60 Echo Please play G# on string %s5%
If %R% EQU 61 Echo Please play A on string %s6%
If %R% EQU 62 Echo Please play A# on string %s6%
If %R% EQU 63 Echo Please play B on string %s6%
If %R% EQU 64 Echo Please play C on string %s6%
If %R% EQU 65 Echo Please play C# on string %s6%
If %R% EQU 66 Echo Please play D on string %s6%
If %R% EQU 67 Echo Please play D# on string %s6%
If %R% EQU 68 Echo Please play E on string %s6%
If %R% EQU 69 Echo Please play F on string %s6%
If %R% EQU 70 Echo Please play F# on string %s6%
If %R% EQU 71 Echo Please play G on string %s6%
If %R% EQU 72 Echo Please play G# on string %s6%
If %R% EQU 73 Echo Please play A on string %s7%
If %R% EQU 74 Echo Please play A# on string %s7%
If %R% EQU 75 Echo Please play B on string %s7%
If %R% EQU 76 Echo Please play C on string %s7%
If %R% EQU 77 Echo Please play C# on string %s7%
If %R% EQU 78 Echo Please play D on string %s7%
If %R% EQU 79 Echo Please play D# on string %s7%
If %R% EQU 80 Echo Please play E on string %s7%
If %R% EQU 81 Echo Please play F on string %s7%
If %R% EQU 82 Echo Please play F# on string %s7%
If %R% EQU 83 Echo Please play G on string %s7%
If %R% EQU 84 Echo Please play G# on string %s7%
If %R% EQU 85 Echo Please play A on string %s8%
If %R% EQU 86 Echo Please play A# on string %s8%
If %R% EQU 87 Echo Please play B on string %s8%
If %R% EQU 88 Echo Please play C on string %s8%
If %R% EQU 89 Echo Please play C# on string %s8%
If %R% EQU 90 Echo Please play D on string %s8%
If %R% EQU 91 Echo Please play D# on string %s8%
If %R% EQU 92 Echo Please play E on string %s8%
If %R% EQU 93 Echo Please play F on string %s8%
If %R% EQU 94 Echo Please play F# on string %s8%
If %R% EQU 95 Echo Please play G on string %s8%
If %R% EQU 96 Echo Please play G# on string %s8%
If %j% EQU a goto opa
If %j% EQU A goto opa
If %j% EQU b goto opb
If %j% EQU B goto opb

:Auto
echo.
Echo Press a key after a note has been generated to generate another note.

:Auto_2
ECHO Press any key to begin.
echo.
pause >nul
Goto Post_input

:opa
sleep -m %y%
goto Post_input

:opb
pause >nul
goto Post_input


Report •


Ask Question