Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
サクラエディタで行をシャッフルする by
Option Explicit
Function DV(A, B)
DV = Fix(A / B)
End Function
Function RD(A, B)
RD = DV(A, B) * B
End Function
Function MD(A, B)
MD = A - RD(A, B)
End Function
Function XR(A, B)
Const N = &H10000
XR = (DV(A, N) Xor DV(B, N)) * N + (MD(A, N) Xor MD(B, N))
End Function
Function SL(A, B)
SL = MD(A, 2 ^ (32 - B)) * (2 ^ B)
End Function
Function SR(A, B)
SR = DV(A, 2 ^ B)
End Function
Function Step1(Y)
Step1 = XR(Y, SL(Y, 13))
End Function
Function Step2(Y)
Step2 = XR(Y, SR(Y, 17))
End Function
Function Step3(Y)
Step3 = XR(Y, SL(Y, 5))
End Function
Function XRS(Y)
XRS = Step3(Step2(Step1(Y)))
End Function
Class Random
Dim Y
Sub Class_Initialize()
Y = 2463534242
End Sub
Function GetValue()
Y = XRS(Y)
GetValue = Y
End Function
Function InInRange(V, R)
If V < R Then
InInRange = V
InInRange = InInRange(GetValue(), R)
End If
End Function
Function InRange(R)
Const X = 4294967295
InRange = MD(InInRange(GetValue(), RD(X, R)), R)
End Function
Function Range(N, X)
Range = InRange(X - N + 1) + N
End Function
End Class
Sub Swap(A, X, Y)
Dim T
T = A(X)
A(X) = A(Y)
A(Y) = T
End Sub
Sub Shuffle(A, R)
Dim I
For I = UBound(A) To LBound(A) + 1 Step -1
Swap A, I, R.Range(0, I)
End Sub
Function GetLineCode()
Dim A
A = Array(vbCrLf, vbCr, vbLf)
GetLineCode = A(Editor.GetLineCode())
End Function
Sub SelectLines(LineStart, LineEnd)
Editor.Jump LineStart
Editor.Jump LineEnd
End Sub
Sub Main()
Dim LineFrom
LineFrom = Editor.GetSelectLineFrom()
Dim LineTo
LineTo = Editor.GetSelectLineTo()
If Editor.GetSelectColmTo() = 1 Then
SelectLines LineFrom, LineTo - 1
SelectLines LineFrom, LineTo
End If
Dim Text
Text = Editor.GetSelectedString(0)
Text = Replace(Text, vbCrLf, vbLf)
Text = Replace(Text, vbCr, vbLf)
Dim A
A = Split(Text, vbLf)
Shuffle A, New Random
Editor.InsText Join(A, GetLineCode())
SelectLines LineFrom, LineTo
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment