Friday, May 13, 2005

VBScript - Random NUmber Generator creates duplicates

VBScript - Random NUmber Generator creates duplicates: "> The only way to guarantee uniqueness is to either:
> 1. Store all possible outcomes and remove an outcome from the list
> when it's chosen until the list count reaches zero (or some arbitrary
> limit)
> 2. Store all chosen outcomes and compare each new choice to the list
> before accepting it.

3. Use GUID based ids...

s = ''
for n = 1 to 5
uniqueid = left(createobject('scriptlet.typelib').guid,38)
'uniqueid = createobject('scriptlet.typelib').guid
'msgbox uniqueid
s = s & uniqueid & vbcrlf
next

' these are each 38 chars long...
'
wscript.echo '1st pass - with curly braces and hyphens' & vbcrlf & s

s = ''
for n = 1 to 5
uniqueid = mid(createobject('scriptlet.typelib').guid,2,36)
s = s & uniqueid & vbcrlf
next

' these are each 36 chars long...
'
wscript.echo '2nd pass - without curly braces' & vbcrlf & s

s = ''
for n = 1 to 5
uniqueid =
replace(mid(createobject('scriptlet.typelib').guid,2,36),'-','')
s = s & uniqueid & vbcrlf
next

' these are each 32 chars long...
'
s = replace(s,'-','')
wscript.echo '3rd pass - without curly braces or hyphens' & vbcrlf & s
"

0 Comments:

Post a Comment

<< Home