"""
Generate random log lines to stdout

Example:

    python generate_random_log.py 1000

will generate 1000 request lines and up to 1000 matching response lines.
"""
import sys
from random import randint

try:
    count = int(sys.argv[1])
except IndexError:
    count = 1

for i in range(0, count):
    hour = randint(0, 23)
    minute = randint(0, 59)

    id = randint(1, 99999)
    duration = randint(0, 20000)
    no_response_failure_rate = randint(0, 99)

    print("08/Apr/2016:%d:%d:47 +0200 [%d] -> GET /content/%s/page.html HTTP/1.1" % (hour, minute, id, "some"))
    if not no_response_failure_rate == 0:
        print("08/Apr/2016:%d:%s:48 +0200 [%d] <- 200 text/html %dms" % (hour, minute, id, duration))

@@ -198,16 +198,398 @@
  randint
+, choice%0A%0A%0Adef mutate(text, mutation_rate):%0A    %22%22%22%0A    For 1 out of %3Cmutation_rate%3E times, insert a random character into a line%0A    %22%22%22%0A    if mutation_rate is None or not randint(0, mutation_rate) == 0:%0A        return text%0A%0A    chars = list(text)%0A    new_char = choice(%5B%22 %22, %22X%22%5D)%0A    position = randint(0, len(text) - 1)%0A    chars%5Bposition%5D = new_char%0A%0A    return %22%22.join(chars)
 %0A%0Atry:%0A 
@@ -841,19 +841,90 @@
 99)%0A
-%0A
     
-print(
+mutation_rate = None # Set to e.g. 100 to damage every 100th line%0A%0A    line = 
 %2208/
@@ -1019,17 +1019,55 @@
  %22some%22)
-)
+%0A    print mutate(line, mutation_rate)%0A
 %0A    if 
@@ -1113,14 +1113,15 @@
     
-print(
+line = 
 %2208/
@@ -1202,10 +1202,51 @@
 uration)
+%0A        print mutate(line, mutation_rate
 )%0A

Generate broken test log lines