I have a list of 15 names and want to run a script that will output these names into a txt file in random order. Is this too tough, or even possible? Any help is appreciated.
The following batch file randomly rearranges and prints its parameters with a probability distribution that is almost uniform.
In the first loop, it assigns a random number to all parameters between zero and 32767 using the built-in variable %random%. Then, it traverses all possible 'rolls' and prints the parameters with matching assigned numbers. If multiple parameters roll the same number, they are echoed in the order they appeared as parameters.
The code is very inefficient, but compact and simple. By reducing the effective range of the random variable, the algorithm can be given a significant speed boost at the cost of increasing bias towards the first specified parameters. Or you could use a proper sorting routine, such as the one specified here.
If you want the batch file to operate on a text file instead of a list of parameters, you can traverse the input with a for-command, adding matches to a space seperated list of strings, e.g.:
Writing to an output file instead of the console can be achieved by either running the batch program as is, redirecting its output with