Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 548837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:07:18+00:00 2026-05-13T11:07:18+00:00

I need to randomly generate a number of values in a batch file that

  • 0

I need to randomly generate a number of values in a batch file that share a certain range and concatenate them together separated by spaces. Everything works except for concatenating the space-separated numbers together. The specific problematic issue is concatenating with the numbers with spaces, how do I go about this?

The relevent portion follows:

::Assume %minA%, %maxA% and %randB% are defined correctly.
set /a randA=(%random% %% %maxA%) + %minA%
set agent_counter=0
:start_agent_loop
if %agent_counter% equ %randA% goto end
set /a randApos=(%random% %% %randB%) + 1
::supposedly (if I recall), simply having a space between %agent_starts%
::and %randApos% should do the trick, this doesn't seem to be the case.
set agent_starts = %agent_starts% %randApos%
set /a agent_counter +=1
goto start_agent_loop

:end
echo -A %agent_starts%

Ideally, this should print something like…

C:\Path\>genparams.bat
-A 2 4 5

Currently I get

-A
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:07:18+00:00Added an answer on May 13, 2026 at 11:07 am

    The following website (SS64.com) is INVALUABLE for batch script reference.
    There are excellent pages on SET, IF, you name it.

    The SET command is not very forgiving with extra whitespace. Also, set /a will apparently check all strings to see if they are a variable, so I don’t think the %’s are required around maxA and minA. I assumed %random% was a special batch file variable that returns a random number, so I did not remove them from that. (though you might be able to)

    Change:

    set /a randA=(%random% %% %maxA%) + %minA%
    

    To:

    set /a randA=(%random%%%maxA)+minA
    

    And change:

    set agent_starts = %agent_starts% %randApos%
    

    To:

    set agent_starts=%agent_starts% %randApos%
    

    Doing that (and setting a minA=1,maxA=10,randB=5), I got this on my first run: “-A 3 4 3”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable that has a number between 1-3. I need to randomly
I need to attach text labels to objects that are spread randomly across the
I have an Array of number values, and I want to randomly select a
I need to randomly generate an two-dimensional n by n array. In this example,
I need to randomly generate three cards from array i have the array of
Is there any way to randomly generate a set of positive numbers such that
So I'm writing a roguelike and I need to generate some dungeons randomly. I
Scenario I am developing an application that intensively use randomly generated values. I have
I need to develop an application that will read and understand text file in
I need to generate random strings in vb.net, which must consist of (randomly chosen)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.