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

Author Topic: random number in dos (xp prompt)  (Read 19382 times)

0 Members and 1 Guest are viewing this topic.

blastman

    Topic Starter


    Hopeful

    random number in dos (xp prompt)
    « 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??

    Blastman, you are the man. Thank You Very Much!!!!!!!!!



    blastman

      Topic Starter


      Hopeful

      Re: random number in dos (xp prompt)
      « Reply #1 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 ;)


      Blastman, you are the man. Thank You Very Much!!!!!!!!!



      Carbon Dudeoxide

      • Global Moderator

      • Mastermind
      • Thanked: 169
        • Yes
        • Yes
        • Yes
      • Certifications: List
      • Experience: Guru
      • OS: Mac OS
      Re: random number in dos (xp prompt)
      « Reply #2 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.

      blastman

        Topic Starter


        Hopeful

        Re: random number in dos (xp prompt)
        « Reply #3 on: June 18, 2008, 09:20:28 AM »
        arh,


        That's much neater.

        Cheers mate.

        Blastman, you are the man. Thank You Very Much!!!!!!!!!



        Carbon Dudeoxide

        • Global Moderator

        • Mastermind
        • Thanked: 169
          • Yes
          • Yes
          • Yes
        • Certifications: List
        • Experience: Guru
        • OS: Mac OS
        Re: random number in dos (xp prompt)
        « Reply #4 on: June 18, 2008, 09:22:47 AM »
        No problem.  ;)