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

Author Topic: Random words in batch?  (Read 14003 times)

0 Members and 1 Guest are viewing this topic.

Batch

    Topic Starter


    Starter

    Random words in batch?
    « on: February 07, 2010, 02:33:34 PM »
    Hey ppl,
    I have a little question, is it possible to create a batch file in witch the program chooses a random word from a list of words that you write in the txt file?
    And what about doing the same but with words and numbers all together?
    I hope u get my point, and yeah, im a noob, so i beg your patience  :P
    Thx!

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: Random words in batch?
    « Reply #1 on: February 07, 2010, 03:41:01 PM »
    Ok. This is what you can use.

    @echo off
    set /a rnd=%random%%%10
    for /f "tokens=1,2" %%a in (list.txt) do if %rnd%==%%a  echo %%b
    pause
    That will get a random number from 1-10 and display a corresponding word.
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    Batch

      Topic Starter


      Starter

      Re: Random words in batch?
      « Reply #2 on: February 07, 2010, 04:28:33 PM »
      Im sorry but could u please explain it? For example, what i am supposed to write in list.txt? And how does it work?   ???
      Sorry but im completely lost here  ::)
      Thanks for answering anyway.

      Helpmeh



        Guru

      • Roar.
      • Thanked: 123
        • Yes
        • Yes
      • Computer: Specs
      • Experience: Familiar
      • OS: Windows 8
      Re: Random words in batch?
      « Reply #3 on: February 07, 2010, 04:44:39 PM »
      Im sorry but could u please explain it? For example, what i am supposed to write in list.txt? And how does it work?   ???
      Sorry but im completely lost here  ::)
      Thanks for answering anyway.
      So, I will start off explaining what needs to be in list.txt. This is what you could put in list.txt

      Quote
      1 Word1
      2 Word2
      3 Word3
      4 Anotherword
      5 ...
      6 get_the_picture?

      Now, I will re-post the script, with comments explaining how the code works.

      @echo off
      rem Turns echoing commands on-screen to off.
      set /a rnd=%random%%%10
      rem Gets a random number from 1-10.
      for /f "tokens=1,2" %%a in (list.txt) do if %rnd%==%%a  echo %%b
      rem Taking the first two tokens of each line in list.txt delimited by spaces,
      rem it will check if the first word is the same as the random number, and if it is,
      rem it will display the second word.
      rem
      pause
      Where's MagicSpeed?
      Quote from: 'matt'
      He's playing a game called IRL. Great graphics, *censored* gameplay.

      Batch

        Topic Starter


        Starter

        Re: Random words in batch?
        « Reply #4 on: February 07, 2010, 05:07:09 PM »
        Oh, ok I get it now.
        Thanks a lot, problem solved!