Imports System.Collections.Generic
Private r As IEnumerator(Of UInteger)
Public Shared ReadOnly defaults As New Dictionary(Of String,UInteger) From {
Public ReadOnly seeds As Dictionary(Of String,UInteger)
Public randCount As UInteger=0
Optional _w As UInteger?=Nothing,
Optional _x As UInteger?=Nothing,
Optional _y As UInteger?=Nothing,
Optional _z As UInteger?=Nothing
Dim w=CUInt(If(_w IsNot Nothing,_w,CUInt(Environment.TickCount)))
Dim x=CUInt(If(_x IsNot Nothing,_x,w<<13))
Dim y=CUInt(If(_y IsNot Nothing,_y,w>>9 Xor x<<6))
Dim z=CUInt(If(_z IsNot Nothing,_z,y>>7))
seeds=New Dictionary(Of String,UInteger) From {
{"x",x},{"y",y},{"z",z},{"w",w}
Public Iterator Function randGen(w As UInteger,x As UInteger,y As UInteger,z As UInteger) As IEnumerator(Of UInteger)
w=(w Xor (w>>19)) Xor (t Xor (t>>8))
Public Function rand() As UInteger
Public Function randInt(Optional min As Integer=0,Optional max As Integer=&H7FFFFFFFI) As Integer
Return CInt(rand() mod (CUInt(max)-min+1)+min)
Public Function randFloat(Optional min As Single=0,Optional max As Single=1) As Single
Return CSng((rand() mod &HFFFFUI)/&HFFFFUI*(max-min)+min)
Public Function shuffle(Of T)(_arr As T()) As T()
Dim arr=CType(_arr.Clone(),T())
Dim r As Integer=randInt(i,arr.Length-1)
Public Function shuffle(Of T)(_arr As List(Of T)) As List(Of T)
Dim arr As New List(Of T)(_arr)
Dim r As Integer=randInt(i,arr.Count-1)
Dim r_def As New XorShift.defaultSeed()
Dim r_const As New XorShift(100)
For Each i In XorShift.defaults.Keys
WriteLine("{0}:{1}",i,XorShift.defaults(i))
WriteLine(">> seeds in r")
For Each i In r.seeds.Keys
WriteLine("{0}:{1}",i,XorShift.defaults(i))
WriteLine(">> rand 0 to UInt32Max")
WriteLine(">> randInt 0 to 100")
WriteLine(r_const.randInt(0,100))
WriteLine(">> randFloat 0 to 1")
WriteLine(">> shuffle Array")
Dim a As Integer()=Enumerable.Range(0,20).ToArray()
WriteLine(String.Join(", ",r.shuffle(a)))
WriteLine(String.Join(", ",a))
WriteLine(">> shuffle List(Of T)")
Dim b As New List(Of Integer)(Enumerable.Range(0,20))
WriteLine(String.Join(", ",r.shuffle(b)))
WriteLine(String.Join(", ",b))
WriteLine(">> randCount in r")