View Full Version : Batch Random Variable
PerpetualImperfexion
October 1st, 2012, 04:58 PM
I know how to generate a random number and assign it to a variable. The problem is that it can be as high as 32000+. Is there a way to generate a random number between two given numbers? Thanks in advance :)
ethanf93
October 1st, 2012, 09:19 PM
I'm not particularly familiar with Microsoft's batch syntax but taking the random number your getting now and "% [HIGHEST NUMBER YOU WANT] + 1" should work. (Replace the brackets with the number)
So:
%random_var% % 100 + 1
The % is the modulo operator, which can be used like +, -, /, etc. It divides the first number by the second and returns the remainder of that division.
TheMatrix
October 2nd, 2012, 12:29 PM
I'm not sure how to do this in Batch(good heavens, why would you do that to yourself!?), but presumably it's similar to this in Perl:
print ranged_rand( 5, 9 );
sub ranged_rand { # "sub" is what PHP users know as "function"
my( $min, $max ) = @_; #This gets the numbers from the arguments passed to the function
my $range = $max - $min;
my $random = int( rand( $range ) ) + $min; #Remove the int() and you will get a long decimal number
return $random;
}
PerpetualImperfexion
October 3rd, 2012, 03:46 PM
I'm not sure how to do this in Batch(good heavens, why would you do that to yourself!?), but presumably it's similar to this in Perl:
print ranged_rand( 5, 9 );
sub ranged_rand { # "sub" is what PHP users know as "function"
my( $min, $max ) = @_; #This gets the numbers from the arguments passed to the function
my $range = $max - $min;
my $random = int( rand( $range ) ) + $min; #Remove the int() and you will get a long decimal number
return $random;
}
:P I'll post the source of my game when I'm done so you can check it out. Its coded completely in batch.
Just need to work out a few kinks and add the leveling portion/player quests. Should be done soon.
Silicate Wielder
October 3rd, 2012, 05:24 PM
I just know the basics to batch you know like
title
echo
pause
open
thats all I know XD
Could you show me where I can learn more about batch?
I want to start working on a 16-bit OS for DOSBox
TheMatrix
October 3rd, 2012, 07:57 PM
I want to start working on a 16-bit OS for DOSBox
I'm not quite sure you know what you're talking about.
Silicate Wielder
October 3rd, 2012, 08:39 PM
I know I don't I just realised I need C and C++ knowledge to even start.
vBulletin® v3.8.9, Copyright ©2000-2021, vBulletin Solutions, Inc.