Hey it works. Better than I could ask for actually... ignoring lines without the syntax and everything.
I made a few little changes to the GUI to make it more windows-like.
Just one thing, could you add a little tag before the text, saying the real percentage, in 100% base denominator? So the text would read "[50%] foobar" instead of just "foobar"...
Thank you for this.
#NoTrayIcon
FileToRead = Todo.txt ;replace "FILE.txt" by the name of the file to read
Sum = 0
AutoTrim,Off
Loop, Read, %FileToRead%,,
{
Flag=false
Loop, parse, A_LoopReadLine, %A_Tab%
{
If Flag=true
continue
Sum +=%A_LoopField%
Flag=true
}
}
Random, Number, 1, Sum
Sum = 0
Line = 0
Loop, Read, %FileToRead%,,
{
Line+=1
Flag=false
Loop, parse, A_LoopReadLine, %A_Tab%
{
If Flag=true
If Sum>=%Number%
{
Message=%A_LoopField%
GoSub, Found
Return
}
Sum +=%A_LoopField%
Probability=%A_LoopField%
Flag=true
}
}
return
Found:
Gui, Add, Picture, x11 y11 Icon5, user32.dll
Gui, Add, Button, gSave x78 y66 w75 h23 +default,&OK
Gui, Add, Button, gRetry x158 y66 w75 h23,&Retry
Gui, Add, Button, gGuiClose x239 y66 w75 h23 , &Cancel
Gui, Add, Edit, vNewProbability x10 y58 w32 h20 Limit4,%Probability%
Gui, Font, s12 w700, Verdana
Gui, Add, Text, x61 y10 w327 h38,%Message%
Gui, Show, xCenter yCenter h101 w395, RandomLine
Return
GuiClose:
ExitApp
Save:
Gui,Submit
FileRead,CompleteFile,%FileToRead%
StringReplace,CompleteFileModified,CompleteFile,``n,`n,ReplaceAll
StringReplace,CompleteFile,CompleteFileModified,%probability%%A_Tab%%message%,%NewProbability%%A_Tab%%message%
FileDelete,%FileToRead%
FileAppend,%CompleteFile%,%FileToRead%
ExitApp
Retry:
Reload