Author Options:

Batch Randomization Answered

so how do you make randomized scenarios in batch because im making a text based game where i need random scenarios like for example get a random customer for a shop game or random skeleton appearing with a randomized amount of hp that you can set.

1 Replies

g-oneBest Answer (author)2017-09-11

@echo off &setlocal

set "customer_1=Peter"

set "customer_2=Paul"

set "customer_3=Mary"

set /a "rnd=%random% %% 3 + 1"

callecho %%customer_%rnd%%%


%random% expands to a number between 0 and 32768. To calculate a number in range 1...3 use the modulus operator (%%) with divisor 3 and add 1.

To expand a nested variable you can use CALL and double the outer percent signs of the variable.

Select as Best AnswerUndo Best Answer