Random GUID type number or RegExp

S

stjulian

I have used

set typ = server.createobject("Scriptlet.TypeLib")

to create a random string of 36 characters. However, is there a way to
create a random string of digits in the length I request? Perhaps a string
of 20 digits with a few asterisks thrown in for ease of typing?

for example:
4515-81301-75454-45136-1

Would this be reated with RegExp? And how?


Julian
 
M

McKirahan

Jon Paal said:
create multiple guid's, concatenate, and read the left 20 characters.

replace hyphens with asterisks

When I do the following:
set typ = server.createobject("Scriptlet.TypeLib")
"typ" contains a 36 byte long string within brackets.

Thus, the OP may want:
typ = Replace(Mid(typ,2,20),"-","*")

typing?

How are asterisks easy to type; why not dashes?

Do you want 20 digits or a string 20 bytes long including the asterisks?
 
D

Dave Anderson

stjulian said:
...is there a way to create a random string of digits
in the length I request? Perhaps a string of 20 digits
with a few asterisks thrown in for ease of typing?

What do you mean by "digits"? Will ANY character on the keyboard do? Do you
have a bias toward numbers? Letters? Does case matter?

Your example had nothing but numbers and a dash, but you suggested that
asterisk and the letters ABCDEF would be fine (since you used GUIDs).

Here's an example that will generate an arbitrary-length string of
"typeable" characters:

function GenerateString(chars) {
for (var i=0,s=""; i<chars; i++)
s += String.fromCharCode(Math.floor(94*Math.random()+33))
return s
}

<%=GenerateString(20)%>


VBScript left as an exercise for the reader.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top