• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Random number

New Here ,
Jul 25, 2007 Jul 25, 2007

Copy link to clipboard

Copied

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?
TOPICS
Advanced techniques

Views

478

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 25, 2007 Jul 25, 2007

Copy link to clipboard

Copied

Try this,
<cfdump var="#RandRange(1,4)##RandRange(1,4)##RandRange(1,4)##RandRange(1,4)#">

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 25, 2007 Jul 25, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 25, 2007 Jul 25, 2007

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 25, 2007 Jul 25, 2007

Copy link to clipboard

Copied

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;
}
return s;
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 25, 2007 Jul 25, 2007

Copy link to clipboard

Copied

Which parts don't you understand?

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2007 Jul 26, 2007

Copy link to clipboard

Copied

To wirte the CF coding..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 26, 2007 Jul 26, 2007

Copy link to clipboard

Copied

LATEST
To write the CF coding..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation