Computing.Net > Forums > Programming > Batch File Random Number

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File Random Number

Reply to Message Icon

Name: jcgun
Date: April 29, 2009 at 11:00:26 Pacific
OS: Windows Vista
Subcategory: Batch
Comment:

Hello,
I want a random fact part of my Batch File, but when i use the %random% command, it crashes.

I believe that this is because '%random%' picks a number between 1 and 32767.

Is there a way of randomly selecting a number between 1 and 10 (that i can change, should i wish to add more facts)



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 29, 2009 at 12:47:16 Pacific
Reply:

set /a R=%random%%10+1


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: jcgun
Date: April 30, 2009 at 03:35:12 Pacific
Reply:

This doesn't work. It gives me numbers like 22335

@echo off
cls
:1
set /a R=%random%%10+1
echo %R%
pause >nul
goto 1


0

Response Number 3
Name: Mechanix2Go
Date: April 30, 2009 at 03:53:07 Pacific
Reply:

@echo off
cls
:1
set /a R=%random%%%10+1
echo %R%
pause >nul
goto 1


=====================================
If at first you don't succeed, you're about average.

M2


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File Random Number

Batch File 'Set' number trouble www.computing.net/answers/programming/batch-file-set-number-trouble/17354.html

batch file programming www.computing.net/answers/programming/batch-file-programming/17121.html

Batch file www.computing.net/answers/programming/batch-file/18005.html