I'm running game servers and I need a batch script that changes a number in another batch-file to a random generated number when executed.

The line that should be edited is set _seed="255"

The file that should be edited looks like that:



ECHO.    =================================================
ECHO.    =                                               =
ECHO.    =             Server Startup Batch              =
ECHO.    =                                               =
ECHO.    =================================================

set _hostname="Server Name"
set _ident="rustide"
set _port="28015"
set _rport="28016"
set _rcon="12345"
set _players="10"
set _level="Procedural Map"
set _seed="255" //This numbers should be replaced by random generated numbers [1-2147483648]
set _worldsize="1000"
set _serverimg=""
set _serverurl="https://www.website.com"
set _serverdesc="Description"

It would be great if somebody could help me doing this, since I'm a complete noob at it.

Any help is appreciated :)


Change your "set _seed" line to be:

set /a _seed=%RANDOM% * 2147483647 / 32768 + 1

This should then generate a random number between 1-2147483647 when the script is run.

EDIT: As pointed out by LotPings in the comments the original max value was too large for Batch to handle so I've edited.

  • Thanks for your answer, but i need to have it in a seperate batch file. Because everytime the server is restarting, the Batchfile above is re-running and would generate a new seed everytime and therefore wipes the server every restart. – dakoza Sep 20 '18 at 15:03
  • @dakoza Ah.. apologies I'd missed that detail when reading the question! – motosubatsu Sep 20 '18 at 15:04
  • Your formula generates invalid numbers as batch only handles 32bit signed integers which has 2147483647 as the highest possible number. – LotPings Sep 20 '18 at 16:38
  • @LotPings You're correct of course! I'm a little rusty on my batch skills evidently! – motosubatsu Sep 21 '18 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.