Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / May 2007



Tip: Looking for answers? Try searching our database.

random numbers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JohnGree - 30 May 2007 11:55 GMT
Hi i did have some code that made up a alfanumeric random number

i know it took from a list of abcdefghijklmnopqrstu0123456789

anyway i have lost it and i need a random afla-numeric does anyone know the
code to do this?
Dan Bracuk - 30 May 2007 13:44 GMT
Generate a random number and convert it to hex.
Adam Cameron - 30 May 2007 14:18 GMT
> Generate a random number and convert it to hex.

That's not going to help with the G-Z part of the alphabet.

To the OP: why are you trying to do this?

To answer your original question:
1) create a list of valid characters, like you have
2) select a random number between 1 and [length of that list]
3) get the character from the list @ that position and store it in your
result string
4) repeat 2-3 until you have a string of the desired length.

Signature

Adam

JohnGree - 30 May 2007 16:29 GMT
hi Adam, that sound like what i had before, but what is the code to do this?
Dan Bracuk - 30 May 2007 17:35 GMT
[q][i]Originally posted by: [b][b]JohnGree[/b][/b][/i]
hi Adam, that sound like what i had before, but what is the code to do this?

[/q]
The functions randrange and listgetat, combined with the concatonation
operator should work.
Adam Cameron - 30 May 2007 23:51 GMT
> hi Adam, that sound like what i had before, but what is the code to do this?

Sorry mate, I rarely provide code for solutions that really oughtn't be too
far from the grasp of the person needing it.  I'm a firm believer in the
"teach a person to fish" approach to problem solving.  Call me a b@st@rd if
you like.

Read the docs.

Or post your code here, and we can go through where it could use
modification.

Signature

Adam

insuractive - 30 May 2007 14:31 GMT
Hex is a good call, as it will prevent any *UNFORTUNATE* letter combinations
BKBK - 31 May 2007 11:21 GMT
The code

<cfset rndm = lcase(replace(CreateUUID(), "-", "", "all"))>
<cfoutput>#rndm#</cfoutput>

will generate a random string of 32 characters from the list
a,b,c,...,f,0,1,2,...,9. You can apply a function like left(), right() and so
on, to obtain a shorter string.
Azadi - 31 May 2007 15:47 GMT
is this the code you have 'lost'?:
http://www.cflib.org/udf.cfm?ID=529

Signature

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.