Skip to content

Instantly share code, notes, and snippets.

@jasonrobot
Last active January 23, 2020 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonrobot/4eac1382dc2e418942749a99f6b57d9c to your computer and use it in GitHub Desktop.
Save jasonrobot/4eac1382dc2e418942749a99f6b57d9c to your computer and use it in GitHub Desktop.
Needed some sample people in a csv file, so gave it a try with Racket. Not bad!
module MakeContacts
extend self
@@onset_list = ["m", "n", "p", "t", "ch", "k", "c", "b", "d", "j", "g", "f", "th", "s", "sh", "h", "v", "l", "r", "w", "pl", "bl", "cl", "gl", "pr", "br", "tr", "dr", "cr", "fl", "sl", "fr", "sm", "sn"]
@@nucleus_list = ["a", "e", "i", "o", "u", "y", "ae", "ai", "au", "ea", "ee", "ei", "ia", "ie", "io", "oa", "oe", "oi", "oo", "ou", "oy", "ue", "ui", "uo"]
@@coda_list = ["m", "n", "p", "t", "ch", "k", "b", "d", "y", "g", "f", "s", "sh", "v", "l", "r", "mb", "mp", "nd", "nt", "nch", "nge", "pt", "tch", "ts", "tsh", "lm", "ln", "lp", "lt", "ld", "lge", "lf", "ls", "rm", "rn", "rp", "rt", "rk", "rb", "rd", "rge", "rf", "rs"]
def get_random_from_list(l)
l[Random.rand(l.size)]
end
def get_balanced_random_from_list(list)
singles = list.select {|s| s.size == 1}
doubles = list.select {|s| s.size == 2}
is_double = Random.rand < 0.3
if is_double
get_random_from_list doubles
else
get_random_from_list singles
end
end
def make_syllable
rand = Random.rand
no_onset = rand < 0.2
no_coda = 0.8 < rand
onset = if (no_onset) "" else get_balanced_random_from_list(@@onset_list) end
nucleus = get_balanced_random_from_list(@@nucleus_list)
coda = if (no_coda) "" else get_balanced_random_from_list(@@coda_list) end
onset + nucleus + coda
end
def make_name(num_of_parts)
Array.new(num_of_parts){ make_syllable }.join
end
def new_contact
first_name = ""
while first_name.size < 3
first_name = make_name(1 + Random.rand(2))
end
last_name = make_name(2 + Random.rand(2))
email = "#{first_name}.test@example.com"
[first_name, last_name, email].join(",")
end
def make_contacts(count)
Array.new(count){ new_contact }
end
end
number_of_contacts = (ARGV[0]? || 10).to_i
puts MakeContacts.make_contacts(number_of_contacts).join("\n")
(defvar onset-list '("m" "n" "p" "t" "ch" "k" "c" "b" "d" "j" "g" "f" "th" "s" "sh" "h" "v" "l" "r" "w" "pl" "bl" "cl" "gl" "pr" "br" "tr" "dr" "cr" "fl" "sl" "fr" "sm" "sn"))
(defvar nucleus-list '("a" "e" "i" "o" "u" "y" "ae" "ai" "au" "ea" "ee" "ei" "ia" "ie" "io" "oa" "oe" "oi" "oo" "ou" "oy" "ue" "ui" "uo"))
(defvar coda-list '("m" "n" "p" "t" "ch" "k" "b" "d" "y" "g" "f" "s" "sh" "v" "l" "r" "mb" "mp" "nd" "nt" "nch" "nge" "pt" "tch" "ts" "tsh" "lm" "ln" "lp" "lt" "ld" "lge" "lf" "ls" "rm" "rn" "rp" "rt" "rk" "rb" "rd" "rge" "rf" "rs"))
(defvar consonant-letters '("m" "n" "p" "b" "f" "v" "t" "d" "k" "g" "l" "r" "w"))
(defun get-random-from-list (l)
(elt l (random (- (length l) 1))))
(defun get-balanced-random-from-list (list)
(let ((singles (remove-if-not (lambda (s) (= 1 (length s))) list))
(doubles (remove-if-not (lambda (s) (= 2 (length s))) list))
(double? (< (random 1.0) 0.3)))
(if double?
(get-random-from-list doubles)
(get-random-from-list singles))))
(defun make-syllable (full-syllable?)
(let* ((rand (if full-syllable?
0.5
(random 1.0)))
(no-onset? (< rand 0.2))
(no-coda? (< 0.8 rand))
(onset (if no-onset? "" (get-balanced-random-from-list onset-list)))
(nucleus (get-balanced-random-from-list nucleus-list))
(coda (if no-coda? "" (get-balanced-random-from-list coda-list))))
(concatenate 'string onset nucleus coda)))
(defun make-name (num-of-parts)
(let ((word ""))
(dotimes (_ num-of-parts word)
(setq word (concatenate 'string word (make-syllable (= num-of-parts 1)))))))
(defun new-contact ()
(let* ((first-name (do ((name "" (make-name (+ 1 (random 2)))))
((< 3 (length name)) name)))
(last-name (make-name (+ 2 (random 2))))
(email (format nil "~a.test@example.com" first-name)))
(format nil "~a,~a,~a" first-name last-name email)))
(defun make-contacts (count)
(let ((contacts '()))
(dotimes (_ count contacts)
(setq contacts (cons (new-contact) contacts)))))
(let* ((argv *posix-argv*)
(argc (length argv))
(number-of-contacts (if (< 1 argc) (parse-integer (elt argv 1)) 10)))
(format t
(concatenate
'string
"fname,lname,email~%"
(reduce (lambda (acc line) (concatenate 'string line "~%" acc))
(make-contacts number-of-contacts)))))
module MakeContacts
extend self
@@onset_list = ["m", "n", "p", "t", "ch", "k", "c", "b", "d", "j", "g", "f", "th", "s", "sh", "h", "v", "l", "r", "w", "pl", "bl", "cl", "gl", "pr", "br", "tr", "dr", "cr", "fl", "sl", "fr", "sm", "sn"]
@@nucleus_list = ["a", "e", "i", "o", "u", "y", "ae", "ai", "au", "ea", "ee", "ei", "ia", "ie", "io", "oa", "oe", "oi", "oo", "ou", "oy", "ue", "ui", "uo"]
@@coda_list = ["m", "n", "p", "t", "ch", "k", "b", "d", "y", "g", "f", "s", "sh", "v", "l", "r", "mb", "mp", "nd", "nt", "nch", "nge", "pt", "tch", "ts", "tsh", "lm", "ln", "lp", "lt", "ld", "lge", "lf", "ls", "rm", "rn", "rp", "rt", "rk", "rb", "rd", "rge", "rf", "rs"]
def get_random_from_list(l)
l[Random.rand(l.size)]
end
def get_balanced_random_from_list(list)
singles = list.select {|s| s.size == 1}
doubles = list.select {|s| s.size == 2}
is_double = Random.rand < 0.3
if is_double
get_random_from_list doubles
else
get_random_from_list singles
end
end
def make_syllable
rand = Random.rand
no_onset = rand < 0.2
no_coda = 0.8 < rand
onset = if (no_onset) then "" else get_balanced_random_from_list(@@onset_list) end
nucleus = get_balanced_random_from_list(@@nucleus_list)
coda = if (no_coda) then "" else get_balanced_random_from_list(@@coda_list) end
onset + nucleus + coda
end
def make_name(num_of_parts)
Array.new(num_of_parts){ make_syllable }.join
end
def new_contact
first_name = ""
while first_name.size < 3
first_name = make_name(1 + Random.rand(2))
end
last_name = make_name(2 + Random.rand(2))
email = "#{first_name}.test@example.com"
[first_name, last_name, email].join(",")
end
def make_contacts(count)
Array.new(count){ new_contact }
end
end
number_of_contacts = (ARGV[0] || 10).to_i
puts MakeContacts.make_contacts(number_of_contacts).join("\n")
#lang racket
(define onset-list '("m" "n" "p" "t" "ch" "k" "c" "b" "d" "j" "g" "f" "th" "s" "sh" "h" "v" #;"z" #;"zh" "l" "r" "w" "pl" "bl" "cl" "gl" "pr" "br" "tr" "dr" "cr" "fl" "sl" "fr" "sm" "sn"))
(define nucleus-list '("a" "e" "i" "o" "u" "y" #;"aa" "ae" "ai" #;"ao" "au" #;"ay" "ea" "ee" "ei" #;"eo" #;"eu" #;"ey" "ia" "ie" #;"ii" "io" #;"iu" #;"ey" "oa" "oe" "oi" "oo" "ou" "oy" #;"ua" "ue" "ui" "uo" #;"uy" #;"ya" #;"ye" #;"yi" #;"yo" #;"yu"))
(define coda-list '("m" "n" "p" "t" "ch" "k" #;"c" "b" "d" "y" "g" "f" "s" "sh" "v" #;"z" #;"zh" "l" "r" #;"w" "mb" "mp" "nd" "nt" "nch" "nge" "pt" "tch" "ts" "tsh" "lm" "ln" "lp" "lt" #;"lch" #;"lk" "ld" "lge" "lf" "ls" "rm" "rn" "rp" "rt" #;"rch" "rk" "rb" "rd" "rge" "rf" "rs"))
(define consonant-letters '("m" "n" "p" "b" "f" "v" "t" "d" "k" "g" "l" "r" "w"))
(define (get-random-from-list l)
(list-ref l (random (- (length l) 1))))
(define (get-balanced-random-from-list list)
(let ((singles (filter (lambda (s) (= 1 (string-length s))) list))
(doubles (filter (lambda (s) (= 2 (string-length s))) list))
(double? (< (random) 0.3)))
(if double?
(get-random-from-list doubles)
(get-random-from-list singles))))
(define (make-syllable)
(let* ((rand (random))
(no-onset? (< rand 0.2))
(no-coda? (< 0.8 rand))
(onset (if no-onset? "" (get-balanced-random-from-list onset-list)))
(nucleus (get-balanced-random-from-list nucleus-list))
(coda (if no-coda? "" (get-balanced-random-from-list coda-list))))
(string-append onset nucleus coda)))
(define (make-name num-of-parts)
(define (iter-syllables count word)
(if (< 0 count)
(iter-syllables (- count 1) (string-append word (make-syllable)))
word))
(iter-syllables num-of-parts ""))
(define (new-contact)
(define (make-first-name)
(let ((name (make-name (+ 1 (random 2)))))
(if (< 3 (string-length name))
name
(make-first-name))))
(let* ((first-name (make-first-name))
(last-name (make-name (+ 2 (random 2))))
(email (format "~a.test@example.com" first-name)))
(format "~a,~a,~a" first-name last-name email)))
(define (make-contacts count)
(define (iter-contacts count contacts)
(if (<= count 0)
contacts
(iter-contacts (- count 1) (cons (new-contact) contacts))))
(iter-contacts count '()))
(let* ((argv (current-command-line-arguments))
(argc (vector-length argv))
(number-of-contacts (if (< 0 argc) (string->number (vector-ref argv 0)) 10)))
(display
(foldl (lambda (acc line) (string-append line "\n" acc))
"fname,lname,email"
(make-contacts number-of-contacts))))
(use-modules (srfi srfi-1))
(use-modules (ice-9 format))
(set! *random-state* (random-state-from-platform))
(define onset-list '("m" "n" "p" "t" "ch" "k" "c" "b" "d" "j" "g" "f" "th" "s" "sh" "h" "v" #;"z" #;"zh" "l" "r" "w" "pl" "bl" "cl" "gl" "pr" "br" "tr" "dr" "cr" "fl" "sl" "fr" "sm" "sn"))
(define nucleus-list '("a" "e" "i" "o" "u" "y" #;"aa" "ae" "ai" #;"ao" "au" #;"ay" "ea" "ee" "ei" #;"eo" #;"eu" #;"ey" "ia" "ie" #;"ii" "io" #;"iu" #;"ey" "oa" "oe" "oi" "oo" "ou" "oy" #;"ua" "ue" "ui" "uo" #;"uy" #;"ya" #;"ye" #;"yi" #;"yo" #;"yu"))
(define coda-list '("m" "n" "p" "t" "ch" "k" #;"c" "b" "d" "y" "g" "f" "s" "sh" "v" #;"z" #;"zh" "l" "r" #;"w" "mb" "mp" "nd" "nt" "nch" "nge" "pt" "tch" "ts" "tsh" "lm" "ln" "lp" "lt" #;"lch" #;"lk" "ld" "lge" "lf" "ls" "rm" "rn" "rp" "rt" #;"rch" "rk" "rb" "rd" "rge" "rf" "rs"))
(define consonant-letters '("m" "n" "p" "b" "f" "v" "t" "d" "k" "g" "l" "r" "w"))
(define (get-random-from-list l)
(list-ref l (random (- (length l) 1))))
(define (get-balanced-random-from-list list)
(let ((singles (filter (lambda (s) (= 1 (string-length s))) list))
(doubles (filter (lambda (s) (= 2 (string-length s))) list))
(double? (< (random 1.0) 0.3)))
(if double?
(get-random-from-list doubles)
(get-random-from-list singles))))
(define (make-syllable full-syllable?)
(let* ((rand (if full-syllable?
0.5
(random 1.0)))
(no-onset? (< rand 0.2))
(no-coda? (< 0.8 rand))
(onset (if no-onset? "" (get-balanced-random-from-list onset-list)))
(nucleus (get-balanced-random-from-list nucleus-list))
(coda (if no-coda? "" (get-balanced-random-from-list coda-list))))
(string-append onset nucleus coda)))
(define (make-name num-of-parts)
(define (iter-syllables count word)
(if (< 0 count)
(iter-syllables (- count 1) (string-append word (make-syllable (= num-of-parts 1))))
word))
(iter-syllables num-of-parts ""))
(define (new-contact)
(define (make-first-name)
(let ((name (make-name (+ 1 (random 2)))))
(if (< 3 (string-length name))
name
(make-first-name))))
(let* ((first-name (make-first-name))
(last-name (make-name (+ 2 (random 2))))
(email (format #f "~a.test@example.com" first-name)))
(format #f "~a,~a,~a" first-name last-name email)))
(define (make-contacts count)
(define (iter-contacts count contacts)
(if (<= count 0)
contacts
(iter-contacts (- count 1) (cons (new-contact) contacts))))
(iter-contacts count '()))
(let* ((argv (command-line))
(argc (length argv))
(number-of-contacts (if (< 0 argc) (string->number (list-ref argv 1)) 10)))
(display
(fold (lambda (acc line) (string-append line "\n" acc))
"fname,lname,email"
(make-contacts number-of-contacts))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment