Skip to content

Instantly share code, notes, and snippets.

@tferr
Created January 6, 2015 16:39
Show Gist options
  • Save tferr/542e3fc1e649f376a10d to your computer and use it in GitHub Desktop.
Save tferr/542e3fc1e649f376a10d to your computer and use it in GitHub Desktop.
ImageJ1 macro function to generate random string
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