random sentence
-
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 -
@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
-
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!
-
thanks for your answer, i shall see with python
-
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…
-
thanks scott
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