Skip to content

Instantly share code, notes, and snippets.

@mmmunk
Created January 6, 2017 13:18
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 mmmunk/6153c7478ef32468c8d2450f71e24dd1 to your computer and use it in GitHub Desktop.
Save mmmunk/6153c7478ef32468c8d2450f71e24dd1 to your computer and use it in GitHub Desktop.
Generate some non-lorem-ipsum random text to use for tests
# fold -s -w 70
import sys
import random
cons = 'bcdfghjklmnpqrstvwxz'
consx = 'hjqvwx'
vows = 'aeiouy'
cvless = 'qxyz'
def generate_word(cap):
if not cap and int(random.random()*100) in range(67, 75):
b = False
size = 1
else:
b = bool(int(random.random()*2))
size = int(random.random()*7)+2
if random.random() < 0.4:
size += 1
if random.random() > 0.8:
size += 2
if random.random() > 0.95:
size += 5
l = []
for i in range(size):
if b:
c = cons[int(random.random()*len(cons))]
d = (i > 0) and (not c in consx) and (random.random() < 0.15)
else:
c = vows[int(random.random()*len(vows))]
d = False
if c in cvless and random.random() > 0.82:
if random.random() < 0.5:
c = 'e'
else:
c = 'a'
b = not b
if i == 0 and cap:
l.append(c.upper())
else:
l.append(c)
if d:
l.append(c)
return ''.join(l)
def generate_line(count_w):
l = []
cap = True
count_nc = 0
numpos = 1+int(random.random()*count_w)*9
for i in range(count_w):
if i == numpos:
word = str(int(random.random()*12000))
else:
word = generate_word(cap)
#TODO: ikke samme word flere gange i træk
count_nc += 1
if count_nc >= 4 and i < count_w-4 and random.random() > 0.8:
word += ','
count_nc = 0
l.append(word)
cap = count_nc > 0 and random.random() < 0.06
return ' '.join(l)
if len(sys.argv) >= 2:
approx_chars = int(sys.argv[1])
else:
approx_chars = 1
if len(sys.argv) >= 3:
words_line = int(sys.argv[2])
para = False
else:
words_line = 0
para = True
char_count = 0
para_line_count = 0
while True:
if para:
line = generate_line(4+int(random.random()*30))
else:
line = generate_line(words_line)
print(line, end='')
char_count += len(line)
if char_count >= approx_chars:
print('.')
char_count += 1
break
if para:
para_line_count += 1
if para_line_count >= 3 and int(random.random()*1000) in range(243, 440):
print('.')
print()
para_line_count = 0
else:
if int(random.random()*89) == 77:
print(' - ', end='')
char_count += 3
else:
if random.random() < 0.02:
print('! ', end='')
elif random.random() > 0.94:
print('? ', end='')
else:
print('. ', end='')
char_count += 2
else:
print('.')
char_count += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment