Created
January 6, 2015 16:39
-
-
Save tferr/542e3fc1e649f376a10d to your computer and use it in GitHub Desktop.
ImageJ1 macro function to generate random string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomString(length, spacers) { | |
template = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
nChars = lengthOf(template); | |
string = ""; | |
for (i=0; i<length; i++) { | |
idx = maxOf(0, round(random()*nChars-1)); | |
string += substring(template, idx, idx+1); | |
if (spacers && i%5==0) string += "_"; | |
} | |
return string; | |
} | |
n = 1; while (n<6) | |
print(n++, randomString(20, true)); | |
n = 1; while (n<6) | |
print(n++, randomString(10, false)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment