|
| 1 | +import string |
| 2 | +import random |
| 3 | +import argparse |
| 4 | + |
| 5 | +def id_generator(size=10, chars=string.ascii_uppercase + string.digits): |
| 6 | + return ''.join(random.choice(chars) for _ in range(size)) |
| 7 | + |
| 8 | +opreators = ["+","-","*","/"] |
| 9 | + |
| 10 | +def get_comment_line(): |
| 11 | + comment_line = "//%s" % (id_generator()) |
| 12 | + return comment_line |
| 13 | + |
| 14 | +def get_float_line(): |
| 15 | + float_line = "f %s" % (random.choice(string.ascii_lowercase)) |
| 16 | + return float_line |
| 17 | + |
| 18 | +def get_integer_line(): |
| 19 | + integer_line = "i %s"% (random.choice(string.ascii_lowercase)) |
| 20 | + return integer_line |
| 21 | + |
| 22 | +def get_asigment_line(): |
| 23 | + asigment_line = "%s = %s" %(random.choice(string.ascii_lowercase),\ |
| 24 | + random.randint(0,100)) |
| 25 | + return asigment_line |
| 26 | + |
| 27 | +def get_asigment_line_2(): |
| 28 | + asigment_line_2 = "%s = %s %s %s" % \ |
| 29 | + (random.choice(string.ascii_lowercase),\ |
| 30 | + random.choice(string.ascii_lowercase),\ |
| 31 | + random.choice(opreators),\ |
| 32 | + random.randint(0,100)) |
| 33 | + return asigment_line_2 |
| 34 | + |
| 35 | +def get_print_line(): |
| 36 | + print_line = "p %s" % (random.choice(string.ascii_lowercase)) |
| 37 | + return print_line |
| 38 | + |
| 39 | + |
| 40 | +parser = argparse.ArgumentParser(description='Generate random AC code') |
| 41 | +parser.add_argument('--stress', dest='stress', action='store_true',\ |
| 42 | + help='generate HUGE code to stress the lab') |
| 43 | +args = parser.parse_args() |
| 44 | + |
| 45 | +if args.stress: |
| 46 | + f= open("random_code.ac","w+") |
| 47 | + for x in range(0, 100000): |
| 48 | + comment_line = get_comment_line() |
| 49 | + float_line = get_float_line() |
| 50 | + integer_line = get_integer_line() |
| 51 | + asigment_line = get_asigment_line() |
| 52 | + asigment_line_2 = get_asigment_line_2() |
| 53 | + print_line = get_print_line() |
| 54 | + |
| 55 | + f.write(comment_line + "\n") |
| 56 | + f.write(float_line + "\n") |
| 57 | + f.write(integer_line + "\n") |
| 58 | + f.write(asigment_line+ "\n") |
| 59 | + f.write(asigment_line_2 + "\n") |
| 60 | + f.write(print_line + "\n") |
| 61 | + |
| 62 | + f.close() |
| 63 | + |
| 64 | +else: |
| 65 | + comment_line = get_comment_line() |
| 66 | + float_line = get_float_line() |
| 67 | + integer_line = get_integer_line() |
| 68 | + asigment_line = get_asigment_line() |
| 69 | + asigment_line_2 = get_asigment_line_2() |
| 70 | + print_line = get_print_line() |
| 71 | + |
| 72 | + print(comment_line) |
| 73 | + print(float_line) |
| 74 | + print(integer_line) |
| 75 | + print(asigment_line) |
| 76 | + print(asigment_line_2) |
| 77 | + print(print_line) |
| 78 | + |
0 commit comments