Is there an easy way in either 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 generate a group of say 500,000 characters :( Any ideas?
+2
A:
Use UUIDGen.
Don't. GUIDs aren't really random. You can actually generate large amounts of data very fast using the System.Random
class in VB.NET. 500,000 characters/bytes are no 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 considerably less than one second.
Konrad Rudolph
2008-12-01 23:29:35
And software random generators aren't truly random, you need a good hardware random generator for that. But for many applications the pseudo random number from the software random generator is random enough.
some
2008-12-01 23:41:41
I think in a programming context we can assume that PRNGs are sufficient, if not otherwise stated. If not, well, yes, then things can get a lot slower (although I've got no experience with the speed of Windows’ entropy generator / hardware random device, which should be close enough to true random).
Konrad Rudolph
2008-12-01 23:48:00
A:
In VB6 the code would go 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
Takes 1/2 second on a 2 Core Intel 2.40 GHz computer.
RS Conley
2008-12-02 13:20:44