Sign in to follow this  
Followers 0
frew

ideas on sorting selected lines in SciTE randomly?

9 posts in this topic

Hello.

I'm wondering if anybody might be able to help me to, in SciTE, select a bunch of lines, and then have the lines be arranged randomly.

So if I have say 5 lines, for example,

1 potato

2 potato

3 potato

4 potato

5 potato

I can just select the 5 lines, run the script, and have the lines get randomized something like this

2 potato

3 potato

5 potato

1 potato

4 potato

(sorry I still do not understand how to really use arrays yet, but I'm trying to figure that out).

Thanks for any ideas,

frew

Share this post


Link to post
Share on other sites



What's the interest ? Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

I have some mp3 links on my site and I like to randomize the arrangement of the links now and then.

So If I just rearrange the lines of links in the html, they show up in a random order on my site.

Without having to deal with editing separate text files whose lines have been randomized, I thought it would be fun to just select some lines of mp3 links in the html and randomize the arrangement of the lines.

Thank you,

frew

Share this post


Link to post
Share on other sites

Try this.

Run script, highlight the lines you want randomized, then press F10 key.

;#include <Array.au3>

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F10}", "RandomizeLines")
HotKeySet("{F9}", "Undo")

While 1
    Sleep(20)
WEnd


Func RandomizeLines()
    Local $aArr, $sClip, $sRes = ""
    Send("^c")
    Send("^c")
    $sClip = ClipGet()
    ;ConsoleWrite($sClip & @CRLF)
    If StringInStr($sClip, @LF) = 0 Then Return
    $aArr = StringRegExp($sClip, "([^\v]+)", 3)
    ;_ArrayDisplay($aArr)
    _ArrayShuffle($aArr)
    For $i = 0 To UBound($aArr) - 1
        $sRes &= $aArr[$i] & @CRLF
    Next
    ClipPut(StringTrimRight($sRes, 2))
    Send("^v")
    ClipPut("")
    Return
EndFunc ;==>RandomizeLines

Func Undo()
    Send("^z")
EndFunc ;==>Undo

Func Terminate()
    Exit 0
EndFunc ;==>Terminate

Func _ArrayShuffle(ByRef $aArr)
    Local $iNo = UBound($aArr) - 1, $iRndNdx, $Temp, $Num
    For $Num = 0 To $iNo
        $iRndNdx = Random(0, $iNo, 1)
        ;Swap
        $Temp = $aArr[$Num]
        $aArr[$Num] = $aArr[$iRndNdx]
        $aArr[$iRndNdx] = $Temp
    Next
EndFunc ;==>_ArrayShuffle

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I have some mp3 links on my site and I like to randomize the arrangement of the links now and then.

So If I just rearrange the lines of links in the html, they show up in a random order on my site.

Without having to deal with editing separate text files whose lines have been randomized, I thought it would be fun to just select some lines of mp3 links in the html and randomize the arrangement of the lines.

Thank you,

frew

Sorry, I understood that you wanted to randomize the lines of a script in scite editor ! Posted Image

Why not randomize lines in your html page ?

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Why not have some Javascript that does it when the page opens? I can whip up an example later if you're interested.

Share this post


Link to post
Share on other sites

Wow, thanks so much Malkey !

That's just what I was hoping to find. It works beautifully.

I really appreciate the help with that.

There may be some other solutions to what I'm trying to accomplish, but this randomizing lines is a lot of fun.

Thanks to all for the other ideas too.

Bye the way, one other thing I've always wished to be able to do is to take a paragraph of text and randomize the word order. Might it be possible to take the code you've provided Malkey, and adjust it to randomize the sort order of words. So for example

One day while walking at the lake, I noticed a huge blue heron looking for some fish.

Might become something like

heron noticed a day walking at One lake, I the fish while huge blue some for looking.

Just curious. That could be a lot of fun too...for creative writing ideas to be generated.

Thank you,

frew

Share this post


Link to post
Share on other sites

When i read the original post, i thought "ok, so this guy's high". and then i read the last post and it's been revised to "this guy is high a LOT". ;) in both cases, the easiest way IMHO would be to throw what you want randomized into an array, then randomly sort the array, and return the results in the new order.


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

....

Bye the way, one other thing I've always wished to be able to do is to take a paragraph of text and randomize the word order. Might it be possible to take the code you've provided Malkey, and adjust it to randomize the sort order of words.

...for creative writing ideas to be generated.

Thank you,

frew

Example 1

One day while walking at the lake, I noticed a huge blue heron looking for some fish.

The next two lines are copies of the above line that have been individually word randomized, one line at a time.

for while at day noticed One looking a walking lake, fish. the heron huge blue I some

lake, day I some huge noticed while looking a heron at fish. the walking One blue for

Example 2

This is what the two lines looked like before they were block highlighted in Notepad and randomized:-

one two three

four five six

And after the RandomizeWords() function was used on both lines by pressing the F8 key. The two lines became :-

five six one two three

four

#include <Array.au3>

HotKeySet("{ESC}", "Terminate")
HotKeySet("{F8}", "RandomizeWords")
HotKeySet("{F9}", "Undo")

While 1
    Sleep(20)
WEnd


Func RandomizeWords()
    Local $aArr, $sClip, $sRes = ""
    Send("^c")
    Send("^c")
    $sClip = ClipGet()
    ;ConsoleWrite($sClip & @CRLF)
    If StringInStr($sClip, " ") = 0 Then Return
    $aArr = StringRegExp($sClip & " ", "([^ ]+) ", 3)
    ;_ArrayDisplay($aArr)
    _ArrayShuffle($aArr)
    For $i = 0 To UBound($aArr) - 1
        $sRes &= $aArr[$i] & " "
    Next
    ClipPut(StringTrimRight($sRes, 1))
    Send("^v")
    ClipPut("")
    Return
EndFunc ;==>RandomizeWords

Func Undo()
    Send("^z")
EndFunc ;==>Undo

Func Terminate()
    Exit 0
EndFunc ;==>Terminate

Func _ArrayShuffle(ByRef $aArr)
    Local $iNo = UBound($aArr) - 1, $iRndNdx, $Temp, $Num
    For $Num = 0 To $iNo
        $iRndNdx = Random(0, $iNo, 1)
        ;Swap
        $Temp = $aArr[$Num]
        $aArr[$Num] = $aArr[$iRndNdx]
        $aArr[$iRndNdx] = $Temp
    Next
EndFunc ;==>_ArrayShuffle
Edited by Malkey

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0