Generating large vb6 / vb net random datasets
3 answers
Use UUIDGen.
not to do. GUIDs are not random. You can actually generate large amounts of data very quickly using a class System.Random
in VB.NET. 500,000 characters / byte is not a problem:
Dim buffer As Byte() = Nothing
Array.Resize(buffer, 500000)
Call New Random().NextBytes(buffer)
My.Computer.FileSystem.WriteAllBytes("filename", buffer, False)
This code takes significantly less than one second.
+3
source to share
In VB6, the code will look something like this:
Public Function FillRandomCol() as Collection
Dim C As Collection
Dim I As Long
Set C = New Collection
Randomize Timer
For I = 1 To 500000
C.Add RandomChar
Next I
Set FillRandomCol = C
End Sub
Public Function Random(ByVal Number As Integer) As Integer
Random = CLng(Rnd * 1000000) Mod Number + 1
End Function
Public Function RandomChar() As String
Const AlphaNum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
RandomChar = Mid$(AlphaNum, Random(36), 1)
End Function
Gains 1/2 second on an Intel 2.40GHz dual core processor.
0
source to share