Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    random sentence

    Help wanted · · · – – – · · ·
    4
    6
    1455
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pouemes
      pouemes last edited by

      Hello all
      i have 8 sentences, i would to copy in my files after an html tag in random one of these 8 sentences
      is it possible with notepad? how?
      thanks

      1 Reply Last reply Reply Quote 0
      • Terry R
        Terry R last edited by

        @pouemes
        If you thinking of using a regular expression (regex) then no. regex does NOT have a calculating ability and no random number generator with which to do an assessment and then pick 1 of 8 sentences.

        However Notepad++ also provides the environment to support some programming languages, such as Pythonscript. Of course this then reduces the support field considerably.

        However there might be a way that regex could ‘emulate’ some randomness. It would depend on what occurs within the html tag. For example if we would select a particular character (say 8th inside the tag), knowing it could be anything within the alphabet it could be possible to select a ‘random’ sentence based on that character’s value. So with 8 sentences you would create 8 lists of characters. Whether they be [a-d], [e-h], [i-l] type or [a,f,u], [b,e,z] types where the characters are random, then this could help in the selection process.

        If you need the 8 sentences to be used only once then the above idea fails.

        Terry

        1 Reply Last reply Reply Quote 4
        • cipher-1024
          cipher-1024 last edited by cipher-1024

          I don’t think NPP has a random number generator. It’s possible you could figure out something with a regex and use the line number or number of characters to get some faux randomness, but that’s beyond my regexpertice. I would use a scripting plugin like Python or Lua to accomplish this.

          EDIT: Terry snuck a better answer in before me!

          1 Reply Last reply Reply Quote 3
          • pouemes
            pouemes last edited by

            thanks for your answer, i shall see with python

            1 Reply Last reply Reply Quote 0
            • Scott Sumner
              Scott Sumner last edited by

              So as a Pythonscript example, this will grab and display a random line from the current file when run:

              from random import randint
              notepad.messageBox(editor.getLine(randint(1, editor.getLineCount()) - 1).rstrip(), 'A random line from active file...')
              

              Note that I’m kinda assuming that the OP’s sentences will be one-per-line in a file…

              1 Reply Last reply Reply Quote 1
              • pouemes
                pouemes last edited by

                thanks scott

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors