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

Vargr name generator in Go

Leitz

SOC-14 1K
Admin Award
Baron
Well, I'm learning Go and needed to make a bunch of Vargr names. Seemed like a good mix. This bit still has the comments in it that allow you to check what's going on under the hood.

Leitz

####
Code:
package main

/* Creates Varg names for the Traveller RPG.
   Traveller is copyright Marc Miller
   This program is provided as is and at no cost, 
   under the Far Future Fair Use Policy.
   See [url]http://farfuture.net/FFEFairUsePolicy2008.pdf[/url]
*/

import "fmt"       // So we can print purty
import "math/rand" // rand
import "time"      // Seed
import "strings"   // Uppercase first character of name

var name string = ""
var lastVowel = false

func randInt(min int, max int) int {
	// Remember to give a max that's 1 above actual max
	return min + rand.Intn(max-min)
}

func C() {
	C := randInt(1, 116)
	fmt.Printf("C is %d.\n", C)

	switch {
	case C <= 5:
		name = name + "d"
	case C <= 10:
		name = name + "dh"
	case C <= 13:
		name = name + "dz"
	case C <= 17:
		name = name + "f"
	case C <= 27:
		name = name + "g"
	case C <= 33:
		name = name + "gh"
	case C <= 35:
		name = name + "gn"
	case C <= 39:
		name = name + "gv"
	case C <= 43:
		name = name + "gz"
	case C <= 53:
		name = name + "k"
	case C <= 56:
		name = name + "kf"
	case C <= 62:
		name = name + "kh"
	case C <= 65:
		name = name + "kn"
	case C <= 68:
		name = name + "ks"
	case C <= 72:
		name = name + "l"
	case C <= 76:
		name = name + "ll"
	case C <= 78:
		name = name + "n"
	case C <= 80:
		name = name + "ng"
	case C <= 85:
		name = name + "r"
	case C <= 89:
		name = name + "rr"
	case C <= 94:
		name = name + "s"
	case C <= 98:
		name = name + "t"
	case C <= 102:
		name = name + "th"
	case C <= 104:
		name = name + "ts"
	case C <= 109:
		name = name + "v"
	case C <= 115:
		name = name + "z"
	}
}

func c() {
	c := randInt(1, 44)
	fmt.Printf("c is %d.\n", c)

	switch {
	case c <= 1:
		name = name + "dh"
	case c <= 2:
		name = name + "dz"
	case c <= 5:
		name = name + "g"
	case c <= 7:
		name = name + "gh"
	case c <= 8:
		name = name + "ghz"
	case c <= 9:
		name = name + "gz"
	case c <= 11:
		name = name + "k"
	case c <= 13:
		name = name + "kh"
	case c <= 14:
		name = name + "khs"
	case c <= 15:
		name = name + "ks"
	case c <= 17:
		name = name + "l"
	case c <= 18:
		name = name + "ll"
	case c <= 23:
		name = name + "n"
	case c <= 28:
		name = name + "ng"
	case c <= 31:
		name = name + "r"
	case c <= 34:
		name = name + "rr"
	case c <= 35:
		name = name + "rrg"
	case c <= 36:
		name = name + "rrgh"
	case c <= 37:
		name = name + "rs"
	case c <= 38:
		name = name + "rz"
	case c <= 39:
		name = name + "s"
	case c <= 40:
		name = name + "th"
	case c <= 41:
		name = name + "ts"
	case c <= 43:
		name = name + "z"
	}
}

func v() {
	V := randInt(1, 27)
	fmt.Printf("V is %d.\n", V)

	switch {
	case V <= 5:
		name = name + "a"
	case V <= 9:
		name = name + "ae"
	case V <= 11:
		name = name + "e"
	case V <= 12:
		name = name + "i"
	case V <= 16:
		name = name + "o"
	case V <= 18:
		name = name + "oe"
	case V <= 20:
		name = name + "ou"
	case V <= 23:
		name = name + "u"
	case V <= 26:
		name = name + "ue"
	}
}

func syllable() {
	var z int

	// Implements the note that syllables that end in a vowel are not followed
	// by a syllable that starts with a vowel
	if lastVowel {
		z = randInt(5, 11)
	} else {
		z = randInt(1, 11)
	}

	fmt.Printf("z is %d.\n", z)

	// C() gives beginning consonants
	// c() gives ending consonants
	// v() gives vowels
	// This switch statement follows the math but not the form
	// of the chart under "Language and Naming". While it gives 
	// The same result it switches VC and CV to allow for 
	// lastVowel to be easier to use.

	switch {
	case z <= 1:
		v()
		lastVowel = true
	case z <= 4:
		v()
		c()
		lastVowel = false
	case z <= 7:
		C()
		v()
		lastVowel = true
	case z <= 10:
		C()
		v()
		c()
		lastVowel = false
	}
}

func main() {
	rand.Seed(time.Now().UTC().UnixNano())

	// Vargr names are rarely longer than 6 syllables 
	nameLength := randInt(1, 7)
	fmt.Printf("Name length is %d.\n", nameLength)

	for i := 0; i < nameLength; i++ {
		syllable()
	}

	fmt.Printf("Name is %s.\n", strings.Title(name))
}
 
Last edited:
Nice!

Have you considered a parser that could pull in the templates for word generation like at https://github.com/makhidkarun/wordgen/blob/master/templates/w.vargr?

Hadn't. I'm not yet as good a programmer as I want to be so this only really uses the random number generator, for, if, and switch. Naturally, the first programming task in any new language, right after "Hello world!" is creating a random number generator. :D

The switch and PRNG use the same math as the CT Vargr book. The templates could probably be done with a multi-level array but I'm not sure they'd provide any difference in output. Might be easier to change though.

Leitz
 
The switch and PRNG use the same math as the CT Vargr book. The templates could probably be done with a multi-level array but I'm not sure they'd provide any difference in output. Might be easier to change though.

I was honestly just thinking that you'd be able to quickly re-use the templates from other languages, which are all in the repo as well. Heh - anyway, that would be my primarily reason for doing it.
 
I've updated the code on Github so that it will generate a verbose explanation of what it's doing, or you can just run it.

Leitz
 
Back
Top