Community
    • Login

    random sentence

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 4 Posters 3.1k Views 2 Watching
    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.
    • pouemesP Offline
      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 RT Offline
        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-1024C Offline
          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
          • pouemesP Offline
            pouemes
            last edited by

            thanks for your answer, i shall see with python

            1 Reply Last reply Reply Quote 0
            • Scott SumnerS Offline
              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
              • pouemesP Offline
                pouemes
                last edited by

                thanks scott

                1 Reply Last reply Reply Quote 1

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors