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 / July 2007



Tip: Looking for answers? Try searching our database.

Random number

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cybersabah - 25 Jul 2007 10:06 GMT
How do i write a CF script can do the random number searching for all the
posibility number like...

Search a 4 digit number like: 1234

Result:
1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412
3421
4123
4132
4213
4231
4312
4321

Anyone can help?
Sankalan - 25 Jul 2007 13:37 GMT
Try this,
<cfdump var="#RandRange(1,4)##RandRange(1,4)##RandRange(1,4)##RandRange(1,4)#">

Thanks
tclaremont - 25 Jul 2007 16:11 GMT
I can't be sure, but I think he is trying to arrive at all of the UNIQUE
numbers that can be created with the digits 1,2,3 and 4.

If that is the case, the previous suggestion will not work. It will merely
return a random number where each of the four digits could be either 1,2,3 or
4. It would also generate duplicates from time to time.
Arbello - 25 Jul 2007 18:07 GMT
If you're not too worried about pegging your server process, you could wrap it
all in if statements.  Write each value randomly generated to a table if it's
not found in the table.  Keep doing this until the table recordcount equals 24.
(God that's messy, on second thought don't listen to me)
cybersabah - 26 Jul 2007 02:09 GMT
Actually i looking for the permutation for the number i searching..  

I found out the function of algorithm to generate permutations frpm Wikipedia,
but no idea how to apply in CF script?

http://en.wikipedia.org/wiki/Permutation

Algorithm to generate permutations
For every number k () this following algorithm generates the corresponding
permutation of the initial sequence :

 function permutation(k, s) {
     var int factorial:= 1;
     for j= 2  to length(s) {
        factorial:= factorial* (j-1);        // factorial= (j-1)!
        swap s[j- ((k / factorial) mod j)] with s[j];
     }
     return s;
 }
Adam Cameron - 26 Jul 2007 07:20 GMT
Which parts don't you understand?

Signature

Adam

cybersabah - 26 Jul 2007 09:47 GMT
To wirte the CF coding..
cybersabah - 26 Jul 2007 09:47 GMT
To write the CF coding..
 
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.