Tuesday, February 23, 2010

Generating Random Data

Do you want to generate random data for your test? Try the below methods.
Method #1:

Set objRandm = CreateObject("Scriptlet.TypeLib")
strGUID = objRandm.Guid
Msgbox strGUID

Method #2:

Set oGuid=DotNetFactory.CreateInstance("System.Guid","mscorlib")
Set oConvert=DotNetFactory.CreateInstance("System.Convert","mscorlib")

temp= oConvert.ToBase64String(oGuid.NewGuid().ToByteArray())
temp=Left(temp,22)
temp=Replace(temp,"/", "_")
strRandm=Replace(temp,"+", "-")
Msgbox strRandm
This method is as same as previous one, but length of the string is shorter.
Method #3:

Msgbox hex(( ( (timer+rnd(1)) *100) + int(rnd(1)*16)*&hf0000 ) mod &h100000 )
The above code generates semi-unique random strings.

No comments:

Post a Comment