Hi,



I have the following code for producing an unique string of 40 characters.
The function is used in an .asp page.



However quite often when the asp page is called the funcion generates
exactly the same string. What can I do more to have the rnd() function get
realy random figures?



function generateGuid

res=""

for nn=1 to 40

res = res & pwletter()

next

generateGuid=res

end function



function pwletter()

do

Randomize()

ss=cint(48+Rnd(Cdbl(Now()))*74)

loop while (ss>=58 and ss<=64) or (ss>=91 and
ss<=96)

pwletter=chr(ss)



end function







Albert Jan

Re: get random string by \

\
Thu Jan 26 08:08:28 CST 2006

> I have the following code for producing an unique string of 40 characters.
> The function is used in an .asp page.

> However quite often when the asp page is called the funcion generates
> exactly the same string. What can I do more to have the rnd() function get
> realy random figures?

Try putting "randomize" outside the loop. Also, this concoction (Cdbl(Now()))
has no more effect on how the random number is generated than any other positive
number, or no number at all. If you really want to have a doubleword number, put
the rnd function in a cdbl wrapper: Cdbl(rnd()). It won't make any difference in
the final number.
http://msdn.microsoft.com/library/en-us/script56/html/618fcba9-cbf2-409b-9963-566e28f67fd1.asp

function generateGuid
res=""
Randomize
for nn=1 to 40
res = res & pwletter()
next
generateGuid=res
end function

function pwletter()
do
ss=cint(48+74*Cdbl(Rnd()))
loop while (ss>=58 and ss<=64) or (ss>=91 and ss<=96)
pwletter=chr(ss)
end function
--
Crash





Re: get random string by mr_unreliable

mr_unreliable
Thu Jan 26 10:28:51 CST 2006

hi Albert,

If you are only looking to generate a guid, there are countless
guid-generating utilities available from the vb source code sites.

Here is one (includes both vb and vb.net versions):

http://www.buygold.net/v01n01/v01n01.html

In addition, if you only trust microsoft code, you can run the
microsoft script component wizard (scriptwz.exe), steal the guid
that was generated, and toss away the rest.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)


Ajw wrote:
> Hi,
>
>
>
> I have the following code for producing an unique string of 40 characters.
> The function is used in an .asp page.
>
>
>
> However quite often when the asp page is called the funcion generates
> exactly the same string. What can I do more to have the rnd() function get
> realy random figures?
>
>
>
> function generateGuid
>
> res=""
>
> for nn=1 to 40
>
> res = res & pwletter()
>
> next
>
> generateGuid=res
>
> end function
>
>
>
> function pwletter()
>
> do
>
> Randomize()
>
> ss=cint(48+Rnd(Cdbl(Now()))*74)
>
> loop while (ss>=58 and ss<=64) or (ss>=91 and
> ss<=96)
>
> pwletter=chr(ss)
>
>
>
> end function
>
>
>
>
>
>
>
> Albert Jan
>
>

Re: get random string by Michael

Michael
Thu Jan 26 20:16:27 CST 2006

Ajw wrote:
> Hi,
>
>
>
> I have the following code for producing an unique string of 40
> characters. The function is used in an .asp page.
>
>

Why not just create true GUIDs (which are less than 40 characters and still
unique)...

A WSH hosted DemoGUID.vbs example...

s = ""
for n = 1 to 5
uniqueid = left(createobject("scriptlet.typelib").guid,38)
s = s & uniqueid & vbcrlf
next
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
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
s = replace(s,"-","")
wscript.echo "3rd pass - without curly braces or hyphens" & vbcrlf & s

>
> However quite often when the asp page is called the funcion generates
> exactly the same string. What can I do more to have the rnd()
> function get realy random figures?
>
>
>
> function generateGuid
>
> res=""
>
> for nn=1 to 40
>
> res = res & pwletter()
>
> next
>
> generateGuid=res
>
> end function
>
>
>
> function pwletter()
>
> do
>
> Randomize()
>
> ss=cint(48+Rnd(Cdbl(Now()))*74)
>
> loop while (ss>=58 and ss<=64) or (ss>=91 and
> ss<=96)
>
> pwletter=chr(ss)
>
>
>
> end function
>
>
>
>
>
>
>
> Albert Jan

--
Michael Harris
Microsoft MVP Scripting

Scripting: Your First Steps
http://www.microsoft.com/technet/scriptcenter/topics/beginner/firststeps.mspx