Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,386 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,189 people online right now. Registration is fast and FREE... Join Now!




Random Function in .bat

 
Closed TopicStart new topic

Random Function in .bat, need help making the random command manually so i can set max limit

coaster3000
post 28 Aug, 2008 - 02:39 PM
Post #1


D.I.C Head

**
Joined: 28 Aug, 2008
Posts: 79


My Contributions


hi i am making a random event generator and i have a few problems that needed fixing.
First i am in need of a random function that is customizable
Or a code for making random numbers but in a variable like %_Rand%
also i need about like 7+ or more random codes for different amounts of numbers allowed in the code and stuff.
I am getting really good at Batch but still need help.. a lot of help
If you need my code just ask just because i am affraid someone will steal this code and post a program before me if there is a pm function then i will give you the code through there

OK seriously i need help with this plus when i am done this entire program i was going to post it for free of use too... sad.gif

This post has been edited by coaster3000: 29 Aug, 2008 - 11:19 AM
User is offlineProfile CardPM

Go to the top of the page

coaster3000
post 29 Aug, 2008 - 01:58 PM
Post #2


D.I.C Head

**
Joined: 28 Aug, 2008
Posts: 79


My Contributions


Ok i really need this random code quick because i am getting really tired of having to wait to post my code

ohh and if there is no double posting sorry

Please someone help me with this.

i just need to know how to make a random function variable using a max value of the random function and a min value... My uncle forgets how to do it... well he is not here right now he is fixing his car right now still for about a day now but please can you help me finish this code... ok just to tell you it is not some kind of homework assignment it is just for fun and games on a site i was oging to post my game i can even post it here when i am done.

PS ... nvm
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 29 Aug, 2008 - 03:36 PM
Post #3


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,402



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


Why are you waiting to show your code?

If you show it, you're more likely to get a response~
User is offlineProfile CardPM

Go to the top of the page

coaster3000
post 29 Aug, 2008 - 03:44 PM
Post #4


D.I.C Head

**
Joined: 28 Aug, 2008
Posts: 79


My Contributions


QUOTE(gabehabe @ 29 Aug, 2008 - 06:36 PM) *

Why are you waiting to show your code?

If you show it, you're more likely to get a response~


I do not want any one to steal it. My uncle (One of the administrators) i do not know his username though said do not post my codes unless i have a copyright or something because he has gottan so many complaints about their work being stolen are you sure i should post it Fine


Posting in a second i have to open my file

EDIT:

here is my code Please do not steal it people but you may modifie it.

I am basically done it but still missing the random codes and the last choice options

CODE
@ECHO OFF
REM This is a BETA File

ECHO welcome to the random event generator
Pause
:LOOP
ECHO Please enter event type
ECHO weather
ECHO dissaster
ECHO (Press Space To QUIT)
SET /p _TYPE=
IF "%_TYPE%"=="weather" GOTO Weather
IF "%_TYPE%"=="dissaster" GOTO Dissaster
IF "%_TYPE%"==" " GOTO QUIT

:Weather
ECHO You Chose Weather
Pause
GOTO W Number 2 Word
:Dissaster
ECHO You Chose Dissaster
Pause
ECHO.
GOTO D Number 2 Word

:WeatherA
Pause

Pause
ECHO Thanks for playing
Pause
CLS
GOTO QUIT

:DissasterA
Pause

Pause
ECHO Thanks for playing
Pause
CLS
GOTO QUIT

:W Number 2 Word
IF ""=="1" SET String1=Sunny
IF ""=="2" SET String1=Cloudy
IF "%String1%"=="Sunny" GOTO Sunny
If "%String1%"=="Cloudy" GOTO Cloudy

:Sunny
IF ""=="1" ECHO Sunny But Windy
IF ""=="2" ECHO Nice Sunny
GOTO WeatherA

:Cloudy
IF ""=="1" SET String2=Cloudy
IF ""=="2" SET String2=Windy
IF ""=="3" SET String2=Rain
IF ""=="4" SET String2=Thunder Storm
IF ""=="5" SET String2=Hurricane
IF "%String2%"=="Cloudy" ECHO Cloudy
IF "%String2%"=="Windy" ECHO  Cloudy but Windy
IF "%String2%"=="Rain" GOTO Rain
IF "%String2%"=="Thunder Storm" GOTO TStorm
IF "%String2%"=="Hurricane" GOTO Hurricane
:Rain
ECHO %String2% , Rain
:TStorm
IF ""=="1" ECHO Thunderstorm
IF ""=="2" SET String3=Severe
IF "%String3%"=="Severe GOTO Severe TStorm
ECHO
:Severe TStorm
IF ""=="1" SET String4=Tornado
IF ""=="2" SET String4=Severe
IF "%String4%"=="Tornado" GOTO Tornadoes
ECHO %String2% , %String4%
:Tornadoes
IF ""=="1" SET String5=F5
IF ""=="2" SET String5=F4
IF ""=="3" SET String5=F3
IF ""=="4" SET String5=F2
IF ""=="5" SET String5=F1
IF ""=="6" SET String5=F0
ECHO %String2% , %String3% , %String4% , %String5%
:Hurricane
IF ""=="1" SET String3=C1
IF ""=="2" SET String3=C2
IF ""=="3" SET String3=C3
IF ""=="4" SET String3=C4
IF ""=="5" SET String3=C5
ECHO %String2% , %String3%
:D Number 2 Word

:QUIT
ECHO You sure you want to quit?Type Yes Or No
SET /P ANSWER=
IF "%ANSWER%"=="Yes" GOTO END
IF "%ANSWER%"=="No" GOTO LOOP
:END


This post has been edited by coaster3000: 29 Aug, 2008 - 03:46 PM
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 30 Aug, 2008 - 04:49 AM
Post #5


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,402



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


No one's going to steal it. Look at it this way~

You need help with it, therefore it doesn't work properly. Why would someone steal that? wink2.gif

You might want to look into the modulus operator. I think this is what you're looking for.

Basically, set /a var = %random% %% 5
So this way, var (in theory) should be between 0 and 4 inclusive.

Now, you can perform if to do something like so:
CODE
set /a var = %random% %% 5
if var == 0 (echo windy)
if var == 1 (echo sunny)
if var == 2 (echo you got struck by lightning)
if var == 3 (echo it's raining cats and dogs!)
if var == 4 (echo better wear your sun cream!)


It's been a while since I did batch, so let me know if this isn't what you're looking for.

Was this helpful?
If it was, click here wink.gif
User is offlineProfile CardPM

Go to the top of the page

coaster3000
post 30 Aug, 2008 - 06:19 AM
Post #6


D.I.C Head

**
Joined: 28 Aug, 2008
Posts: 79


My Contributions


thanks i am giong to input that into there now biggrin.gif

EDIT wait how do i limit it by a number is it like this %% 5 for top number allowed is 5 and like %% 10 means like the top number allowed is ten thats all now because i need to make 7 of these random codes smile.gif


OK i tried this it brings this up

QUOTE

Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).
Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).
Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).
welcome to the random event generator
Press any key to continue . . .


This post has been edited by coaster3000: 30 Aug, 2008 - 06:29 AM
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 30 Aug, 2008 - 07:15 AM
Post #7


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,402



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


You're looking to make one random number between 1 and 7, and perform an if statement to output one particular thing, correct?

set /a var = %random% %% 7
The available numbers will be:
0, 1, 2, 3, 4, 5, 6

So, perform an if on each of those to determine what needs to be performed.

I'm off until tomorrow now, but I'll check back to this thread as soon as I come back. smile.gif

Edit:
My bad~ I told you it's been a while. Here, this should work to give you an idea:
CODE
@echo off
set /a var = %random% %% 5
if %var%==0 (echo windy)
if %var%==1 (echo sunny)
if %var%==2 (echo you got struck by lightning)
if %var%==3 (echo it's raining cats and dogs!)
if %var%==4 (echo better wear your sun cream!)
pause


Hope this helps smile.gif
User is offlineProfile CardPM

Go to the top of the page

coaster3000
post 30 Aug, 2008 - 07:37 AM
Post #8


D.I.C Head

**
Joined: 28 Aug, 2008
Posts: 79


My Contributions


QUOTE(gabehabe @ 30 Aug, 2008 - 10:15 AM) *

You're looking to make one random number between 1 and 7, and perform an if statement to output one particular thing, correct?

set /a var = %random% %% 7
The available numbers will be:
0, 1, 2, 3, 4, 5, 6

So, perform an if on each of those to determine what needs to be performed.

I'm off until tomorrow now, but I'll check back to this thread as soon as I come back. smile.gif

Edit:
My bad~ I told you it's been a while. Here, this should work to give you an idea:
CODE
@echo off
set /a var = %random% %% 5
if %var%==0 (echo windy)
if %var%==1 (echo sunny)
if %var%==2 (echo you got struck by lightning)
if %var%==3 (echo it's raining cats and dogs!)
if %var%==4 (echo better wear your sun cream!)
pause


Hope this helps smile.gif


Hmmm well ok ok so i think there is another problem now LOL Why does it happen to me LOL

ok i will paste what it shows up
QUOTE
You sure you want to quit?Type Yes Or No
No
Please enter event type
weather
dissaster
(Press Space To QUIT)
weather
You Chose Weather
Press any key to continue . . .
The syntax of the command is incorrect.
The syntax of the command is incorrect.
Press any key to continue . . .


Ok so now the syntax is wrong let me try to figure this one out this time if not i will edi tthis post and tell if it worked or not after a few minor adjustments


!!!!!!!!!!!! IT WORKS yay i am so happy thank you so much but i think i am going to make a v2 because the way you represented the example gave me an idea thank you so much!!!!!

I am clicking on you this post was helpfull whatever it does!!

This post has been edited by coaster3000: 30 Aug, 2008 - 07:49 AM
User is offlineProfile CardPM

Go to the top of the page

Closed TopicStart new topic
Time is now: 11/22/08 06:43AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month