Unfortunately I'm unable to add comments to an existing StackOverflow article as my rep isn't high enough, so I'll reference the link here: runonce-to-rename-a-computername-with-a-random-name-on-reboot
Why does the batch sample code that LotPings provided always prefix the randomly generated part with the first letter from the character list, e.g. "A"?
Sample code:
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
Set "Chars=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
Call :RandChar 26 Name
For /L %%A in (1,1,14) Do Call :RandChar 62 Name
Echo %Name%
Goto :Eof
:RandChar Range Var
Set /A Pnt=%Random% %% %1 & Set %2=!%2!!Chars:~%Pnt%,1!
Result when executed 10 times:
AOyVq8olMi7kZaR
ANyU2MoAzZwTpwo
AYNXqJSGKXgyvca
AFGoCImfNOHuVSz
AHNhxnj9Wyqkqo3
AML6hTrSHK4TFut
AHuinBZCWr5D5NZ
AQYNtXaYMXRdGOb
ARWYXn7YNMQ0cmm
APHdWggSQl5KUhA
How can the code be modified to randomise the starting character too?