50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
import time
|
|
import random
|
|
from sys import stdout
|
|
import argparse
|
|
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("-b-min", type=int, help="burst minimum", default=1)
|
|
ap.add_argument("-b-max", type=int, help="burst maximum", default=20)
|
|
ap.add_argument("-d-min", type=int, help="sleep minimum ms", default=0)
|
|
ap.add_argument("-d-max", type=int, help="sleep maximum ms", default=3000)
|
|
ap.add_argument("-between", type=int, help="between maximum ms", default=1000)
|
|
ap.add_argument("-n", type=int, help="max to gen", default=14)
|
|
ap.add_argument("-w", type=int, help="weight scalar", default=1)
|
|
ap.add_argument("-r-min", type=float, help="rotation interval min", default=1500)
|
|
ap.add_argument("-r-max", type=float, help="rotation interval max", default=5000)
|
|
args = ap.parse_args()
|
|
|
|
random.seed(int(1000*time.time()))
|
|
|
|
def new_burst():
|
|
return random.randint(args.b_min, args.b_max)
|
|
def new_between():
|
|
return random.randint(0, args.between) / 1000.0
|
|
def new_delay():
|
|
return random.randint(args.d_min, args.d_max) / 1000.0
|
|
def new_rotation_deadline():
|
|
return time.time() + random.randint(args.r_min, args.r_max) / 1000.0
|
|
def new_rotation():
|
|
return random.randint(0, args.n-1)
|
|
|
|
pool = []
|
|
for i in range(args.n):
|
|
pool.extend([i for _ in range(i**args.w)])
|
|
burst = new_burst()
|
|
rotation_deadline = new_rotation_deadline()
|
|
rotation = new_rotation()
|
|
while True:
|
|
line = (pool[random.randint(0, len(pool)-1)] + rotation) % args.n
|
|
if burst:
|
|
print(line, file=stdout)
|
|
stdout.flush()
|
|
time.sleep(new_between())
|
|
burst -= 1
|
|
if not burst:
|
|
time.sleep(new_delay())
|
|
burst = new_burst()
|
|
if time.time() >= rotation_deadline:
|
|
rotation = (rotation + new_rotation()) % args.n
|
|
rotation_deadline = new_rotation_deadline()
|