• Login
Community
  • Login

random sentence

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 4 Posters 2.4k Views
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.
  • P
    pouemes
    last edited by Nov 12, 2018, 10:27 AM

    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
    • T
      Terry R
      last edited by Nov 12, 2018, 6:51 PM

      @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
      • C
        cipher-1024
        last edited by cipher-1024 Nov 12, 2018, 6:57 PM Nov 12, 2018, 6:56 PM

        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
        • P
          pouemes
          last edited by Nov 13, 2018, 10:05 AM

          thanks for your answer, i shall see with python

          1 Reply Last reply Reply Quote 0
          • S
            Scott Sumner
            last edited by Nov 13, 2018, 1:13 PM

            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
            • P
              pouemes
              last edited by Nov 13, 2018, 4:52 PM

              thanks scott

              1 Reply Last reply Reply Quote 1
              1 out of 6
              • First post
                1/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors