Computer Hope

Microsoft => Microsoft DOS => Topic started by: blastman on June 18, 2008, 09:07:49 AM

Title: random number in dos (xp prompt)
Post by: blastman on June 18, 2008, 09:07:49 AM
hey guys,

I'm writing a game and I'd like to have a few random things happen.

I've used %random% to generate a number but the number is allways very simlier to tha last one.

I had intended to get a ramdom number, divided by 2 and then do a if gtr then do.... if lss than do.... but beacuse the number is allways around the 170** range.


example

test.bat

@echo off

Code: [Select]
set num=%random%
echo %num%

set /a num=%num% / 2
echo %num%

if /i "%num%" GTR "16384" (echo number low) else echo number low

set num=

pause

any ideas??
Title: Re: random number in dos (xp prompt)
Post by: blastman on June 18, 2008, 09:12:52 AM
thing about it,

I've just grabbed the last digit as it allways changes and used that instead;


set num=%random%

set /a num=%num% / 2

set /a num=%num:~3,2%

if /i "%num%" GEQ "5" (echo number high) else echo number low

set num=

pause

job done.

Cheers anyways guys   ;D ;)

Title: Re: random number in dos (xp prompt)
Post by: Carbon Dudeoxide on June 18, 2008, 09:17:54 AM
What about this:

Set /a Number=(%Random% %%10)+1

That will generate a number between 1 and 10.
Title: Re: random number in dos (xp prompt)
Post by: blastman on June 18, 2008, 09:20:28 AM
arh,


That's much neater.

Cheers mate.
Title: Re: random number in dos (xp prompt)
Post by: Carbon Dudeoxide on June 18, 2008, 09:22:47 AM
No problem.  ;)