Generating large vb6 / vb net random datasets

Is there an easy way in any language to generate a large set of random data quickly so far all the functions I've tried haven't worked too well when I need to create a group of 500,000 characters :( Any ideas

+1


source to share


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


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


Use UUIDGen . At least the pieces will be bigger.

-1


source







All Articles