• Welcome to the new COTI server. We've moved the Citizens to a new server. Please let us know in the COTI Website issue forum if you find any problems.
  • We, the systems administration staff, apologize for this unexpected outage of the boards. We have resolved the root cause of the problem and there should be no further disruptions.

Simple Character UPP generator

Leitz

SOC-14 1K
Admin Award
Baron
All, we were talking about alternate methods of rolling up characters elsewhere and so I fixed mine to let you roll with a minimum on the die. It uses python 2 and should run on Windows as well.

Leitz

####
Code:
#!/usr/bin/env python

import random
import argparse

parser = argparse.ArgumentParser(description="Deal with Options")
parser.add_argument('-m', action='store', type=int , dest='min_die_roll',  help='Minimum Die Roll, single Die')

args = parser.parse_args()
min_die_roll = args.min_die_roll

def roller(n_die, min_die_roll=1):
  result = 0
  for x in xrange(n_die):
    result += random.randint(min_die_roll,6)
  return result

UPP = []
upp = ''

for y in xrange(6):
  roll = "%X" % roller(2, min_die_roll)
  UPP.append(roll)
  upp = upp + UPP[y]

print "UPP: %s" %  upp
 
Last edited:
I just plugged this into Python 2.7 and get an error on line 20.
The argument to int() must a string or a number.

Looks interesting, so I'll probably muck with it later today.
 
I just saw that argparse is Python 2.7 or later. Ugh!

If you're getting an error on line 20, then remove the "x" from "xrange". That's a Python 2-3 issue.
 
I counter with a Classic Language version, submitted with tongue in cheek:

(runs in Chipmunk Basic, probably any other "OSB")
Code:
10 rem UPP generation
20 def fn r() = rnd(6) + rnd(6) + 2
30 upp$ = ""
40 for i = 1 to 6
50 upp$ = upp$ + hex$(fn r())
60 next i
70 print "UPP:", ucase$(upp$)

Or a more "sci fi" Classic Language: (runs in gforth, which is synonymous with Traveller in my mind due to me playing with both of them at the same time.)

Code:
require random.fs
: 2d    6 random 6 random + 2 + ;
: .x    hex s>d <# # #> type decimal ;
: .upp  6 0 do 2d .x loop cr ;
 
I'm no programmer but I toyed with some html a few years back and came up with this
Code:
<html>
<body>
Roll 6 Characteristics using 2d6 for each <INPUT NAME="Button1" TYPE="BUTTON" 

VALUE="ROLL" onClick="Button1_onClick()">
</FORM>
<script type="text/javascript">
	function Button1_onClick() 
		{
		for(i = 0; i < 6; i++)
			{	
			r = randomNumber(1, 6) + randomNumber(1, 6)
			switch (i)
				{
				case 0: document.write("STR = "); break;
				case 1: document.write("DEX = "); break;
				case 2: document.write("END = "); break;
				case 3: document.write("INT = "); break;
				case 4: document.write("EDU = "); break;
				case 5: document.write("SOS = "); break;
				default: document.write("ERROR switch i");
				}	 
			if (r<10)
				{
				document.write(r)
				}
			else
				{
				switch (r)
					{
					case 10: document.write("A"); break;
					case 11: document.write("B"); break;
					case 12: document.write("C"); break;
					default: document.write("ERROR switch R");
					}
				}
			document.write("<br>")	
			}		
		document.close()
		}
	
	function randomNumber(VarMin, VarMax) 
		{
		return Math.round(Math.random()*(VarMax-VarMin))+VarMin;
		}
</SCRIPT>
<p> </p>
</body>
</html>
 
Code:
#
#   Simple Character UPP Generator for Python 2.5.4
#   (Original code by Leitz)
#
###################################################

import random

min_die_roll = 1

def roller(n_die, min_die_roll):
  result = 0
  for x in range(n_die):
    result += random.randint(min_die_roll,6)
  return result

upp = ''

for y in range(6):
  upp = upp + "%X" % roller(2, min_die_roll)

print "UPP: %s" %  upp
 
Perl:


print "$_: " . (int(rand(6)) + int(rand(6)) + 2) . "\n" foreach qw/STR DEX END INT EDU SOC/;


At least, I think that will work. Ah, but for just the UPP:

print hex(int(rand(6)) + int(rand(6)) + 2) . "\n" for 1..6;

I'm sure Python has a similar one-liner, as does Ruby.
 
Last edited:
Yes. But I wanted to stay with Leitz's original code, out of respect. As well as keep the code readable.

Bah! Readable! If it was hard to write, it should be hard to read... :) Just kidding, you're right, since this sort of code snippet is usually part of a larger codebase.

However, if all you want is a UPP, then good solid boilerplate code can get in the way. Perhaps I'm splitting hairs, but it needs to be said. No, I'm not a codger, me! Now get off of my lawn, sonny...!
 
Bah! Readable! If it was hard to write, it should be hard to read... :) Just kidding, you're right, since this sort of code snippet is usually part of a larger codebase.

However, if all you want is a UPP, then good solid boilerplate code can get in the way. Perhaps I'm splitting hairs, but it needs to be said. No, I'm not a codger, me! Now get off of my lawn, sonny...!

My one-liner so far. Not too confusing... yet.

Code:
#
#   Very Simple Character UPP Generator for Python 2.5.4
#
#########################################################

from random import randint

for i, j in enumerate(['STR','DEX','END','INT','EDU','SOC']): print j + ": %X" % (randint(1,6) + randint(1,6))
 
Shonner, I was just working on that. :)

# Python 2.6.6

import random

for s in ['STR', 'DEX', 'END', 'INT', 'EDU', 'SOC']:
... print("%s: %d" % (s, random.randint(1,6) + random.randint(1,6)))


# Results example output:
STR: 5
DEX: 10
END: 8
INT: 5
EDU: 3
SOC: 8
 
I kept expecting someone to come up with an Assembler blurb. C wouldn't be too hard, I think.
 
I used C to do a 68000 assembler version for my TI-89. The code is too long to be posting here, with its proprietary syscalls to the screen refresh and keyboard waits.
 
C would be similarly trivial if we had a random number library. I'm sure there is one nowadays. Right?

Something like

char* chr[] = ["STR", "DEX", ...etc... ];

for( j=0; j<6; j++ )
printf( "%s: %d\n", chr[j], rand() * 6 + 1 );
 
Okay, so I've been wanting to (re) learn Go for a while. Here's a snippet that creates a character. It also runs the random number generator a lot so you can see how random it actually is.

Code:
package main

import "math/rand"
import "fmt"
import "time"

func randInt( min int, max int ) int {
    return min + rand.Intn(max - min)
}


var number_array [15]int
var stats = [6]string {"Str", "Dex", "End", "Int", "Edu", "Soc"}

func main () {

    rand.Seed( time.Now().UTC().UnixNano())

    for _,v := range stats {
        x := randInt(1, 7)
        y := randInt(1, 7)
        z := x + y 
        fmt.Printf("%s: %d\n", v, z)
    }   
        
    for a := 0; a <= 1000 ; a = a + 1 { 
        x := randInt(1, 7)
        y := randInt(1, 7)
        z := x + y 
        number_array[z]++ 
    }   

    for k,v := range number_array {
        fmt.Printf("Key: %d  and Value: %d.\n", k, v )
    }

    return
}

Here are the results of a run:

Code:
go run die_roller.go
Str: 10
Dex: 7
End: 9
Int: 9
Edu: 4
Soc: 8
Key: 0  and Value: 0.
Key: 1  and Value: 0.
Key: 2  and Value: 29.
Key: 3  and Value: 60.
Key: 4  and Value: 91.
Key: 5  and Value: 128.
Key: 6  and Value: 123.
Key: 7  and Value: 152.
Key: 8  and Value: 142.
Key: 9  and Value: 121.
Key: 10  and Value: 84.
Key: 11  and Value: 49.
Key: 12  and Value: 22.
Key: 13  and Value: 0.
Key: 14  and Value: 0.
 
Back
Top