Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Generate number between 1 and 4  (Read 2654 times)

0 Members and 1 Guest are viewing this topic.

blueeyce

  • Guest
Generate number between 1 and 4
« on: June 08, 2006, 09:00:04 AM »
Is is possible in DOS to generate a number in a given range? Thank you

carlos

  • Guest
Re: Generate number between 1 and 4
« Reply #1 on: June 08, 2006, 09:43:12 AM »
Are you using the console of WXP or DOS 6.X ?

If you're running Windows, you can do:

set /a %RANDOM% % 4 + 1

To generate a number between 1 and 4.

blueeyce

  • Guest
Re: Generate number between 1 and 4
« Reply #2 on: June 08, 2006, 10:28:03 AM »
I'm using the console in Win2k and I get a "missing operator" from your code. Any ideas?
« Last Edit: June 08, 2006, 10:33:37 AM by blueeyce »

GuruGary



    Adviser
    Re: Generate number between 1 and 4
    « Reply #3 on: June 08, 2006, 10:55:35 PM »
    The command Carlos gave should work if you paste it directly on the command line.  If you want to use it in a batch file, double up on the percent sign before the 4

    Command line:
    Code: [Select]
    set /a %RANDOM% % 4 + 1
    Batch file:
    Code: [Select]
    @echo off
    set /a rnd=%RANDOM% %% 4 + 1
    echo %rnd%

    blueeyce

    • Guest
    Re: Generate number between 1 and 4
    « Reply #4 on: June 09, 2006, 04:51:35 AM »
    Perfect, thank you very much.