I wanted a simple way to generate 6 D&D Character Abilities scores using Linux. There are the classic methods of using a spreadsheet, but what if I don't want numbers in a spreadsheet? What if I merely need them displayed on the screen or in a text file?
Well... terminal can do that with the
shuf command. Open a terminal and try this command:
shuf -i 3-18 -n6 | paste - -s -d ' '
Breaking it down,
shuf will select a seemingly random number. -i is the input of an expected range, in this case 3 to 18 or 3-18. The headcount or the number of numbers generated in this fashion is -n6. Everything after the pipe | is formating. Basically, this part will turn the typical column of numbers into a row of numbers.
If you play D&D like me, you let players re-roll ones. In this case, your command would need to cover a range of 6 to 18. Two times three dice is 6. Try this line:
shuf -i 6-18 -n6 | paste - -s -d ' '
Ok. That's great. You get six numbers in a row on your screen. What if you want that in a text file? For sanity, use the
cd command to move from wherever you are to the Documents folder. (I lose lots of files and time by NOT doing this...)
Now that you are in a safe place, let's add some information to that line of commands:
shuf -i 3-18 -n6 | paste - -s -d ' ' > Stats.txt
> Stats.txt at the end will create a file called "Stats.txt" in your current directory.
Go open that file:
Great. That is one character's worth of stats. Let's make more:
shuf -i 3-18 -n6 | paste - -s -d ' ' >> Stats.txt
Note the double >> symbols. All that does is tell terminal to append the current information to the file described. Note: I clipped my screen to show gedit and terminal in one screen shot for the next step.
Repeat the last command with a small modification, change
-i 3-18 to
-i 6-18. Since you didn't close gedit, you will get a new button which refreshes the file. Before you do, repeat the
shuf command again. This is easily done by pressing the up arrow and then return. Do this twice.
Ok, now hit that refresh command. You have 4 sets of stats, where the first two have a range of 3 and 18 and the second is 6 and 18.
Shuf is not exactly a random number generator, but it's good enough for government work* and character stats. I THINK it is using it's the process id time and doing a computation based on that value. That means if you run a bunch of these commands in rapid succession and that interval is less than a second, then the seemingly random numbers will all be the same or very close to it. This is why I didn't make it generate 6 character at a time. You probably can't hit up arrow + return in less than half a second so the effect is not as noticeable.
Lastly, you could always run
info shuf to see the full documentation of this command or to read at your convenience, try
info shuf > Infoonshuf.txt
*This is joke. DON'T use this to generate random numbers for government work.