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

Author Topic: How do you print one of three words at random?  (Read 3935 times)

0 Members and 1 Guest are viewing this topic.

DarkendHeart

    Topic Starter


    Beginner

    Thanked: 1
    How do you print one of three words at random?
    « on: June 16, 2008, 01:03:54 AM »
    Ok I'm trying to set it up so when a certain variable is equal to a certain thing Dos picks from three predetermined words and echos on of them at random, any way at doing this?

    macdad-



      Expert

      Thanked: 40
      Re: How do you print one of three words at random?
      « Reply #1 on: June 16, 2008, 06:19:46 AM »
      try this

      Code: [Select]
      set word1=<watever phrase>
      set word2=<wateverphrase>
      set word3=<wateverphrase>
      if '%<watever variable>%'=='<watever thing>' (
      set /a rnd=%random% %%3 + 1 >nul
      if '%rnd%'=='1' (
      echo %word1%
      pause
      exit)
      if '%rnd%'=='2' (
      echo %word2%
      pause
      exit)
      if '%rnd%'=='3' (
      echo %word3%
      pause
      exit)
      )


      ok this part states the three preditermined words
      Code: [Select]
      set word1=<watever phrase>
      set word2=<wateverphrase>
      set word3=<wateverphrase>

      this creates a random number( between 1 and 3)
      Code: [Select]
      set /a rnd=%random% %%3 + 1 >nul
      does this work for you?
      If you dont know DOS, you dont know Windows...

      Thats why Bill Gates created the Windows NT Family.

      DarkendHeart

        Topic Starter


        Beginner

        Thanked: 1
        Re: How do you print one of three words at random?
        « Reply #2 on: June 16, 2008, 08:48:45 AM »
        Yeah, works like a charm thanks!

        macdad-



          Expert

          Thanked: 40
          Re: How do you print one of three words at random?
          « Reply #3 on: June 16, 2008, 03:54:47 PM »
          your quite welcome, if you need help with anything else, give one of us a holler  ;)
          If you dont know DOS, you dont know Windows...

          Thats why Bill Gates created the Windows NT Family.

          DarkendHeart

            Topic Starter


            Beginner

            Thanked: 1
            Re: How do you print one of three words at random?
            « Reply #4 on: June 18, 2008, 03:56:07 AM »
            Well now I'm having issues again. For some reason or another dos doesn't like these lines of code.
            Code: [Select]
            @echo off
            set DC1=10
            if '%DC1%'=='10' (
            set /a ST=%random% %%3 + 1 >null
            pause
            if '%ST%'=='3' (
            pause
            set DC1= King
            goto :Done
            )
            if '%ST%'=='2' (
            pause
            set DC1= Queen
            goto :Done
            )
            if '%ST%'=='1' (
            pause
            set DC1= Jack
            goto :Done
            )
            goto :DC2
            )
            :DC2
            echo %DC1%, this is DC2.
            pause
            :Done
            echo %DC1%, this is DONE.
            pause
            The two different done statements aren't going to be apart of the finial code its just there so I know if its even running threw the other if statements. Now I'm guessing it has some thing to do with having the if statements inside a unfinished if statement but I'm not completely sure on this. It always prints "10" to the screen instead of one of the three words and it always hits DC2 instead of DONE so it appears to me for some reason or another its ignoring
            Code: [Select]
            pause
            if '%ST%'=='3' (
            pause
            set DC1= King
            goto :Done
            )
            if '%ST%'=='2' (
            pause
            set DC1= Queen
            goto :Done
            )
            if '%ST%'=='1' (
            pause
            set DC1= Jack
            goto :Done
            )
            I know it picks a random number because it creates the null file but after that it just jumps for no reason. None that I can see atleast. Thanks in advance for all help.

            Sidewinder



              Guru

              Thanked: 139
            • Experience: Familiar
            • OS: Windows 10
            Re: How do you print one of three words at random?
            « Reply #5 on: June 18, 2008, 06:01:46 AM »
            I'm guessing KISS doesn't live here anymore. I probably missed something,  but why make this so complicated?

            Code: [Select]
            @echo off
            set DC1=10
            if '%DC1%'=='10' set /a ST=%random% %%3 + 1
            if '%ST%'=='3' set DC1= King
            if '%ST%'=='2' set DC1= Queen
            if '%ST%'=='1' set DC1= Jack

            echo %DC1%, this is OVER DONE.

            Sometimes fall thru logic makes sense. ST can only have one value per run, so it drops thru the values that are false.

             8)

            The true sign of intelligence is not knowledge but imagination.

            -- Albert Einstein

            macdad-



              Expert

              Thanked: 40
              Re: How do you print one of three words at random?
              « Reply #6 on: June 18, 2008, 06:14:52 AM »
              ok i change it so there isnt the if statement inside the other if.  and also i changed the null because this ">null" makes a file, this doesnt ">nul".

              Code: [Select]
              @echo off
              set DC1=10
              if '%DC1%'=='10' (
              set /a ST=%random% %%3 + 1 >nul
              pause
              )
              if '%ST%'=='3' (
              pause
              set DC1=King
              goto :Done
              )
              if '%ST%'=='2' (
              pause
              set DC1=Queen
              goto :Done
              )
              if '%ST%'=='1' (
              pause
              set DC1=Jack
              goto :Done
              )
              goto :DC2
              :DC2
              echo %DC1%, this is DC2.
              pause
              :Done
              echo %DC1%, this is DONE.
              pause
              does this work?
              If you dont know DOS, you dont know Windows...

              Thats why Bill Gates created the Windows NT Family.

              DarkendHeart

                Topic Starter


                Beginner

                Thanked: 1
                Re: How do you print one of three words at random?
                « Reply #7 on: June 18, 2008, 04:11:22 PM »
                Works great, thanks again for the help.