Brian Dunning's FileMaker Custom Functions

xShuffle ( INPUT ; TIMES )

To shuffle a string

  Average rating: 4.1 (22 votes) Log in to vote

Nick Lightbody   Nick Lightbody - Show more from this author
Deskspace Systems Limited
http://deskspace.com

Share on Facebook Share on Twitter

  Sample input:
"abcdefghijklmnopqrstuvwxyz";99
  Sample output:
xzfrijqpkymcuswvbhdetolnga

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This is a simple tail recursive function used to create a shuffled string for substitution in an encryption process. Typically the process will use a large number of such substitution strings and hence the need to create a large series required this function.

Each cycle moves random character to the end of the string, hence TIMES must be larger than the length of the string.

 

Comments

unix   unix, Japan
Jan 13, 2016
Parameter names are different from definition.

Why don't you use control to selecting character to move?
1st call you need to select from all chars.
2nd call you need to select from all chars excluding last one, it is already selected before.
and so on.
 
Nick   Nick, Sussex UK
Jan 13, 2016
Thanks - I have amended the parameter names.
When creating a block of keys, we normally shuffle the normal set of characters say a 1000 times, as it is very quick. In practice the quality of the result is no different.
With a longer set of characters, in Japan, perhaps this could be more of an issue?
However, on a random shuffle it is best, I think, to select from all every time, not to exclude the last one, since otherwise it is surely less random?
Cheers, Nick
 
comment   comment, VR
Jan 16, 2016
"Each cycle moves random character to the end of the string, hence TIMES must be larger than the length of the string."

If you select a random character one at time, move it from the input string to the output string and repeat this until you run out of characters, you will end up with a completely randomized string. There will never be a need to it more times than the length of the input string.
 
unix   unix, Japan
Jan 20, 2016
xs ( INPUT ; OUTPUT )
/*
INPUT: string to shuffle
OUTPUT:call with ""
*/
Let ( [
l = Length ( INPUT ) ;
r = Int ( Random * L ) + 1
] ;
Case ( l < 2 ; OUTPUT & INPUT ; xs ( Replace ( INPUT ; r ; 1 ; "" ) ; OUTPUT & Middle ( INPUT ; r ; 1 ) ) )
)
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: