Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: How to make a random 15 digit number


Message #1 by "Sebastiaan Janssen" <genuine2001@h...> on Mon, 28 Jan 2002 15:05:24
Hello,



How would I go about generating a completely random number that exists of 

exactly 15 digit and doesn't exist in my database?



Well, I could generate it and then check in my database whether it 

exists, if it does I could regenerate one. 



But how do I get 15 random digits?! :)



Thanks!

Sebastiaan.
Message #2 by Joe Ingle <Joe@k...> on Mon, 28 Jan 2002 02:51:26 -0000
<%

function gen_key(digits)

Dim char_array(50)



char_array(0) 	= "0"

char_array(1) 	= "1"

char_array(2) 	= "2"

char_array(3) 	= "3"

char_array(4) 	= "4"

char_array(5) 	= "5"

char_array(6) 	= "6"

char_array(7) 	= "7"

char_array(8) 	= "8"

char_array(9) 	= "9"



randomize

do while len(output) < digits

num = char_array(Int((9 - 0 + 1) * Rnd + 0))

output = output + num

loop



gen_key = output

end function



response.write (""&gen_key(15)&"")

%>

-----Original Message-----

From: Sebastiaan Janssen [mailto:genuine2001@h...]

Sent: Monday, January 28, 2002 03:05

To: ASP Web HowTo

Subject: [asp_web_howto] How to make a random 15 digit number





Hello,



How would I go about generating a completely random number that exists of 

exactly 15 digit and doesn't exist in my database?



Well, I could generate it and then check in my database whether it 

exists, if it does I could regenerate one. 



But how do I get 15 random digits?! :)



Thanks!

Sebastiaan.




$subst('Email.Unsub').

Message #3 by Oleg Kapeljushnik <c-oleg.kapeljushnik@w...> on Mon, 28 Jan 2002 10:10:57 -0500
you can create 15 different digits separately and then connect it together

like a string result = n1 & n2 & n3 ...

or as numbers result = n1 * 1 + n2 * 10 + n3 * 100 + n4 * 1000 + ..



my suggestion make a loop.



Oleg



-----Original Message-----

From: Sebastiaan Janssen [mailto:genuine2001@h...]

Sent: January 28, 2002 3:05 PM

To: ASP Web HowTo

Subject: [asp_web_howto] How to make a random 15 digit number





Hello,



How would I go about generating a completely random number that exists of

exactly 15 digit and doesn't exist in my database?



Well, I could generate it and then check in my database whether it

exists, if it does I could regenerate one.



But how do I get 15 random digits?! :)



Thanks!

Sebastiaan.




$subst('Email.Unsub').



Message #4 by "Sebastiaan Janssen" <genuine2001@h...> on Mon, 28 Jan 2002 15:31:19
Works perfectly! Thanks!





> <%

> function gen_key(digits)

> Dim char_array(50)

> 

> char_array(0) 	= "0"

> char_array(1) 	= "1"

> char_array(2) 	= "2"

> char_array(3) 	= "3"

> char_array(4) 	= "4"

> char_array(5) 	= "5"

> char_array(6) 	= "6"

> char_array(7) 	= "7"

> char_array(8) 	= "8"

> char_array(9) 	= "9"

> 

> randomize

> do while len(output) < digits

> num = char_array(Int((9 - 0 + 1) * Rnd + 0))

> output = output + num

> loop

> 

> gen_key = output

> end function

> 

> response.write (""&gen_key(15)&"")

> %>

> -----Original Message-----

> From: Sebastiaan Janssen [mailto:genuine2001@h...]

> Sent: Monday, January 28, 2002 03:05

> To: ASP Web HowTo

> Subject: [asp_web_howto] How to make a random 15 digit number

> 

> 

> Hello,

> 

> How would I go about generating a completely random number that exists 

of 

> exactly 15 digit and doesn't exist in my database?

> 

> Well, I could generate it and then check in my database whether it 

> exists, if it does I could regenerate one. 

> 

> But how do I get 15 random digits?! :)

> 

> Thanks!

> Sebastiaan.




> $subst('Email.Unsub').


  Return to Index