Generate Random StringsI wrote this code to generate a random string. I was wondering if there are better or alternative ways to do this without a for loop.
names default to here(1);
letters={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
randstrlength=100;
randstr="";
for(ii=1, ii<=randstrlength, ii++,
randstr=randstr || letters[Random Integer(26)];
);
randstr;Re: Generate Random StringsThank you for allowing me to use your example, @brady_brady ! Now that will be shared with users, in the product. I have updated the description and examples. Yours will be an intriguing and playful example to read 

Re: Generate Random StringsYes, and to illustrate that, here is the result J( 10, 3... ) is used instead of J ( 10, 1, ... ) in the example I gave earlier (note: I didn't show the whole log... the first 20 lines of printing are not shown. Also please ignore the literary abuses like "21th", "22th", etc. )

Re: Generate Random StringsHi everyone,
Two quick things to add.
1) If you don't like the big long list assignment (I don't either), you can do this to get your character set:
charset = words("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "");
I do this all the time, from sheer laziness. If you need multiple-character strings, just use a delimiter

2) Technically, J in fact DOES loop... quickly. It returns a matrix, but can do whatever you like inside the loop. Below, a Nixonian denial is printed each time through the loop, and a matrix of Fibonacci numbers is returned. Note that i, the index, is initialized outside, and incremented within, the loop.
i = 1;
J( 10, 1,
print(evalinsert("For the ^i^^if(i < 4, words(\!"st,nd,rd\!",\!",\!")[i], \!"th\!")^ time, I'm not a loop!"));
round(1/sqrt(5)*((1+sqrt(5))/2)^i++)
);

Re: Generate Random StringsI think that the J() function is under-appreciated. It evaluates its third argument for each element in a row-wise order. There is so much one can do with it without explicitly looping in JSL. Thanks for improving the Scripting Guide with more extensive examples.
Re: Generate Random Strings@SamGardner @Mark_Bailey this is really an important subject. Generating a vector of random numbers is important in statistical computing.
I made changes in JMP18 OSI, so the existing single line examples look like this

now become something like this:

Re: Generate Random StringsI know the goal was to avoid looping, but the long line of code that contained all the letters was bugging me. Here's a way to use the ascii table to generate the random chars. It didn't work with the J() command, since that expects numbers. Perhaps someone can get this to work with without having to use a loop.
randstrlength = 100;
lstchars = {};
for each ({i}, 1::randstrlength,
lstchars[i]= hex to char (right(Hex(64+Random integer (26), "integer"),2));
);
randstr = concat items (lstchars, "");
Re: Generate Random StringsThanks! Here is it, much simpler approach:
Names Default To Here( 1 );
randomString = Function( { length }, { letters },
letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
Return( concat items(letters[J( length, 1, Random Integer( 1, length ) ) ], "") );
);
Show( randomString( 10 ) );Re: Generate Random Strings @SamGardner "concat items" has a second argument, which you can directly use and avoid a substitute to be more efficient.
Re: Generate Random Stringsbased on @Mark_Bailey and @peng_liu contributions, this seems to work well
Names Default To Here( 1 );
randomString = Function( { length }, { letters },
letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
Return( substitute(concat items(letters[J( length, 1, Random Integer( 1, length ) ) ]), " ", "") );
);
Show( randomString( 10 ) );
had to use the substitute command to get rid of spaces between the characters.
Re: Generate Random StringsNames Default To Here( 1 );
randomString = Function( { length }, { letters },
letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
Return( letters[J( length, 1, Random Integer( 1, length ) ) ] );
);
Show( randomString( 10 ) );Re: Generate Random Stringsnames default to here(1);
letters={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
randstrlength=100;
idx = J(1,randstrlength, Random Integer(26));
randstr=concat items(letters[idx], "");
Hooyah! Magic! 
Re: Generate Random StringsI cannot think of how to do it without a loop. Random Integer does not return a random vector. Random Index returns a vector, but no duplicates.
I can only think of being more efficient. Concatenating strings in a loop is not efficient. The following should improve a little bit.
names default to here(1);
letters={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
randstrlength=100;
idx = J(1,randstrlength);
for(ii=1, ii<=randstrlength, ii++,
idx[ii] = Random Integer(26);
);
randstr=concat items(letters[idx], "");
I am wondering about the existence of a no-loop solution, too 