Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Randomize with VBSCRIPT

Status
Not open for further replies.

kasandoro

IS-IT--Management
Feb 11, 2003
11
US
Hello! I'm trying to create an 8-character string of completely random hex numbers using the current time and date of the computer...down to the millisecond. How is this possible with VBscript?

Here's my current code, and it does work sort of, but it's not completely random, and the results can range from between 1 and 9 characters, not always hex. Any help would be GREATLY appreciated!

-----------------
set oshell=CreateObject("Wscript.Shell")
set objFSO=CreateObject("Scripting.FileSystemObject")
logfile="results.csv"

if objfso.fileexists(logfile) then
objfso.deletefile logfile
end if

Set ofile=objFSO.CreateTextFile(logfile,True)
startime=Second(Now)

Do Until second(now)-startime >=3
strdate=Day(Now)&Hour(Now)&Minute(Now)&Second(Now)&Right(Timer(),3)
Randomize
MyNumber = Int(rnd() * strdate)
ofile.write Hex(mynumber)&vbcrlf
Loop
---------------------

As you can see, I only have it run for three seconds to get an adequate cross-section to test for duplicates in Excel. Once this is completed, the file-creation portion of the code will be removed and this will need to create a random string of 8 characters, always in Hex format, to be used as a machine name (using a custom build CD for our company).

Thanks again, for any help anyone can provide!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top