Friday, January 10, 2020

Stupid Hobby Collision D&D+Linux

I like Linux and D&D. Rarely do these hobbies collide, but sometimes I can force it. Not that I am a great Linux user. I like Linux. I like Ubuntu with XFCE. It's a great environment for my purposes. I am newbie when it comes to terminal skills. This post assumes you have zero skill.

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...)

cd Documents


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


The instruction > 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.

4 comments:

  1. Well, shuf just shuffles an array of the numbers around, so you will not get a character with two of the same attributes (WIS 9 and DEX 9), will you? Then there is the distribution of the numbers as well. With shuf STR 3 is equally probable as a STR of 10. This is definitly not a 3d6 distribution.

    ReplyDelete
  2. Under normal circumstances, shuf will read data from a file and rearrange it. In this example, since I have given it no reference, I *think* it's using it's own thread information to generate "random numbers". It's not random, just obscure. So, this method could generate two identical values.

    In the examples above, the first is generating numbers between 3 and 18 and the second is 6-18. Both are totally flat, like you had a die labeled with exactly that number range. It is very different from 3d6.

    I don't see this as a problem for generating scores, as it's so fast, any junk characters could be wiped and rerolled in half a jiff. Or upcycled into NPC, like butchers, bakers and chandlers.

    It would be horrible for die rolls at the table which use two or more dice (such as fireball damage). It would be fine for 1d20 for attacks and saves.

    ReplyDelete
  3. I've been using `rolldice` for a while now, which seems to be packaged for Ubuntu:

    https://packages.ubuntu.com/eoan/rolldice

    Nice clean syntax for rolling, e.g. for ability scores:

    $ rolldice 6x3d6
    12 6 11 7 13 13

    In any case I do enjoy having the results in the terminal, ready to scroll back up through if I want to reconstruct the events of a combat, for instance.

    ReplyDelete