def quick_test(): def floor_mod_10(x): return _math.floor(x) % 10 print("\nMonkeyScope: RNG Tests") start = _time.time() print("\nBoolean Variate Distributions\n") distribution_timer(bernoulli_variate, 1 / 3) distribution_timer(bernoulli_variate, 2 / 3) print("\nInteger Variate Distributions\n") print("Base Case") distribution_timer(_random.randint, 1, 6) distribution_timer(uniform_int_variate, 1, 6) distribution_timer(binomial_variate, 4, 0.5) distribution_timer(negative_binomial_variate, 5, 0.75) distribution_timer(geometric_variate, 0.75) distribution_timer(poisson_variate, 4.5) print("\nFloating Point Variate Distributions\n") print("Base Case") distribution_timer(_random.random, post_processor=round) distribution_timer(generate_canonical, post_processor=round) print("Base Case") distribution_timer(_random.uniform, 0.0, 10.0, post_processor=_math.floor) distribution_timer(uniform_real_variate, 0.0, 10.0, post_processor=_math.floor) print("Base Case") distribution_timer(_random.expovariate, 1.0, post_processor=_math.floor) distribution_timer(exponential_variate, 1.0, post_processor=_math.floor) print("Base Case") distribution_timer(_random.gammavariate, 1.0, 1.0, post_processor=_math.floor) distribution_timer(gamma_variate, 1.0, 1.0, post_processor=_math.floor) print("Base Case") distribution_timer(_random.weibullvariate, 1.0, 1.0, post_processor=_math.floor) distribution_timer(weibull_variate, 1.0, 1.0, post_processor=_math.floor) distribution_timer(extreme_value_variate, 0.0, 1.0, post_processor=round) print("Base Case") distribution_timer(_random.gauss, 5.0, 2.0, post_processor=round) distribution_timer(normal_variate, 5.0, 2.0, post_processor=round) print("Base Case") distribution_timer(_random.lognormvariate, 1.6, 0.25, post_processor=round) distribution_timer(lognormal_variate, 1.6, 0.25, post_processor=round) distribution_timer(chi_squared_variate, 1.0, post_processor=_math.floor) distribution_timer(cauchy_variate, 0.0, 1.0, post_processor=floor_mod_10) distribution_timer(fisher_f_variate, 8.0, 8.0, post_processor=_math.floor) distribution_timer(student_t_variate, 8.0, post_processor=round) end = _time.time() duration = round(end - start, 4) print(f"\nTotal Test Time: {duration} seconds")
def quick_test(): print("\nMonkeyScope: Fortuna Quick Test") print("\nRandom Sequence Values:\n") start_test = _time.time() some_list = [i for i in range(10)] print(f"some_list = {some_list}\n") print("Base Case") distribution_timer( _random.choice, some_list, label="Random.choice(some_list)" ) distribution_timer( random_value, some_list, label="random_value(some_list)" ) print("\nWide Distribution\n") truffle = TruffleShuffle(some_list) print("Truffle = TruffleShuffle(some_list)") distribution_timer(truffle, label="Truffle()") truffle = truffle_shuffle(some_list) print("truffle = truffle_shuffle(some_list)") distribution_timer(truffle, label="truffle()") print("\nSingle objects with many distribution possibilities\n") some_tuple = tuple(i for i in range(10)) print("some_tuple = tuple(i for i in range(10))\n") monty = QuantumMonty(some_tuple) print("monty = QuantumMonty(some_tuple)") distribution_timer(monty, label="monty()") rand_value = RandomValue(some_tuple) print(f"rand_value = {rand_value}") distribution_timer(rand_value, label="rand_value()") print("\nWeighted Tables:\n") population = ("A", "B", "C", "D") cum_weights = (1, 3, 6, 10) rel_weights = (1, 2, 3, 4) cum_weighted_table = zip(cum_weights, population) rel_weighted_table = zip(rel_weights, population) print(f"population = {population}") print(f"cum_weights = {cum_weights}") print(f"rel_weights = {rel_weights}") print(f"cum_weighted_table = zip(cum_weights, population)") print(f"rel_weighted_table = zip(rel_weights, population)\n") print("Cumulative Base Case") distribution_timer( _random.choices, population, cum_weights=cum_weights, label="Random.choices(population, cum_weights=cum_weights)" ) cum_weighted_choice = CumulativeWeightedChoice(cum_weighted_table) print("cum_weighted_choice = CumulativeWeightedChoice(cum_weighted_table)") distribution_timer(cum_weighted_choice, label="cum_weighted_choice()") distribution_timer( cumulative_weighted_choice, tuple(zip(cum_weights, population)), label="cumulative_weighted_choice(tuple(zip(cum_weights, population)))" ) print("Relative Base Case") distribution_timer( _random.choices, population, weights=rel_weights, label="Random.choices(population, weights=rel_weights)" ) rel_weighted_choice = RelativeWeightedChoice(rel_weighted_table) print("rel_weighted_choice = RelativeWeightedChoice(rel_weighted_table)") distribution_timer(rel_weighted_choice, label="rel_weighted_choice()") print("\nRandom Matrix Values:\n") some_matrix = { "A": (1, 2, 3, 4), "B": (10, 20, 30, 40), "C": (100, 200, 300, 400) } print(f"some_matrix = {some_matrix}\n") print('flex_cat = FlexCat(some_matrix)') flex_cat = FlexCat(some_matrix) distribution_timer(flex_cat, label='flex_cat()') distribution_timer(flex_cat, "C", label='flex_cat("C")') print("\nRandom Integers:\n") print("Base Case") distribution_timer(_random.randrange, 10) distribution_timer(random_below, 10) distribution_timer(random_index, 10) distribution_timer(random_range, 10) distribution_timer(random_below, -10) distribution_timer(random_index, -10) distribution_timer(random_range, -10) print("Base Case") distribution_timer(_random.randrange, 1, 10) distribution_timer(random_range, 1, 10) distribution_timer(random_range, 10, 1) print("Base Case") distribution_timer(_random.randint, -5, 5) distribution_timer(random_int, -5, 5) print("Base Case") distribution_timer(_random.randrange, 1, 20, 2) distribution_timer(random_range, 1, 20, 2) distribution_timer(random_range, 1, 20, -2) distribution_timer(random_range, 20, 1, -2) distribution_timer(d, 10) distribution_timer(dice, 3, 6) distribution_timer(ability_dice, 4) distribution_timer(plus_or_minus, 5) distribution_timer(plus_or_minus_linear, 5) distribution_timer(plus_or_minus_gauss, 5) print("\nRandom Floats:\n") print("Base Case") distribution_timer(_random.random, post_processor=round) distribution_timer(canonical, post_processor=round) distribution_timer(random_float, 0.0, 10.0, post_processor=_math.floor) print("Base Case") distribution_timer(_random.triangular, 0.0, 10.0, 5.0, post_processor=round) distribution_timer(triangular, 0.0, 10.0, 5.0, post_processor=round) print("\nRandom Booleans:\n") distribution_timer(percent_true, 33.33) print("\nShuffle Performance:\n") shuffle_cycles = 7 small, medium, large = 10, 100, 1000 some_small_list = list(range(small)) print(f"some_small_list = [i for i in range({small})]") some_med_list = list(range(medium)) print(f"some_med_list = [i for i in range({medium})]") some_large_list = list(range(large)) print(f"some_large_list = [i for i in range({large})]") print("\nBase Case:") print("Random.shuffle()") timer(_random.shuffle, some_small_list, cycles=shuffle_cycles) timer(_random.shuffle, some_med_list, cycles=shuffle_cycles) timer(_random.shuffle, some_large_list, cycles=shuffle_cycles) some_small_list.sort() some_med_list.sort() some_large_list.sort() print("\nFortuna.shuffle()") timer(shuffle, some_small_list, cycles=shuffle_cycles) timer(shuffle, some_med_list, cycles=shuffle_cycles) timer(shuffle, some_large_list, cycles=shuffle_cycles) print("\nFortuna.knuth_a()") timer(knuth_a, some_small_list, cycles=shuffle_cycles) timer(knuth_a, some_med_list, cycles=shuffle_cycles) timer(knuth_a, some_large_list, cycles=shuffle_cycles) print("\nFortuna.fisher_yates()") timer(fisher_yates, some_small_list, cycles=shuffle_cycles) timer(fisher_yates, some_med_list, cycles=shuffle_cycles) timer(fisher_yates, some_large_list, cycles=shuffle_cycles) print("\n") print("-" * 73) stop_test = _time.time() print(f"Total Test Time: {round(stop_test - start_test, 3)} seconds")
def monty_tests(): print("\nQuantum Monty Methods:\n") monty = QuantumMonty(range(10)) distribution_timer(monty.flat_uniform) distribution_timer(monty.front_linear) distribution_timer(monty.middle_linear) distribution_timer(monty.back_linear) distribution_timer(monty.quantum_linear) distribution_timer(monty.front_gauss) distribution_timer(monty.middle_gauss) distribution_timer(monty.back_gauss) distribution_timer(monty.quantum_gauss) distribution_timer(monty.front_poisson) distribution_timer(monty.middle_poisson) distribution_timer(monty.back_poisson) distribution_timer(monty.quantum_poisson) distribution_timer(monty.quantum_monty)
def lambda_monty_tests(): print() print("Quantum Monty Methods ala Lambda") print() monty = QuantumMonty(( lambda x: f"A: {d(x)}", lambda x: f"B: {d(x)}", lambda x: f"C: {d(x)}", lambda x: f"D: {d(x)}", lambda x: f"E: {d(x)}", lambda x: f"F: {d(x)}", lambda x: f"G: {d(x)}", lambda x: f"H: {d(x)}", )) d_size = 2 distribution_timer(monty.flat_uniform, x=d_size) distribution_timer(monty.front_linear, x=d_size) distribution_timer(monty.middle_linear, x=d_size) distribution_timer(monty.back_linear, x=d_size) distribution_timer(monty.quantum_linear, x=d_size) distribution_timer(monty.front_gauss, x=d_size) distribution_timer(monty.middle_gauss, x=d_size) distribution_timer(monty.back_gauss, x=d_size) distribution_timer(monty.quantum_gauss, x=d_size) distribution_timer(monty.front_poisson, x=d_size) distribution_timer(monty.middle_poisson, x=d_size) distribution_timer(monty.back_poisson, x=d_size) distribution_timer(monty.quantum_poisson, x=d_size) distribution_timer(monty.quantum_monty, x=d_size)
def quick_test(): R = _random.Random() num_cycles = 10000 print("\nMonkeyScope: Pyewacket\n") start_test = _time.time() print("Base Case") distribution_timer(R._randbelow, 10, num_cycles=num_cycles) distribution_timer(randbelow, 10, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.randint, 1, 10, num_cycles=num_cycles) distribution_timer(randint, 1, 10, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.randrange, 0, 10, 2, num_cycles=num_cycles) distribution_timer(randrange, 0, 10, 2, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.random, post_processor=round, num_cycles=num_cycles) distribution_timer(random, post_processor=round, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.uniform, 0.0, 10.0, post_processor=_math.floor, num_cycles=num_cycles) distribution_timer(uniform, 0.0, 10.0, post_processor=_math.floor, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.expovariate, 1.0, post_processor=_math.floor, num_cycles=num_cycles) distribution_timer(expovariate, 1.0, post_processor=_math.floor, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.gammavariate, 2.0, 1.0, post_processor=round, num_cycles=num_cycles) distribution_timer(gammavariate, 2.0, 1.0, post_processor=round, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.weibullvariate, 1.0, 1.0, post_processor=_math.floor, num_cycles=num_cycles) distribution_timer(weibullvariate, 1.0, 1.0, post_processor=_math.floor, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.betavariate, 3.0, 3.0, post_processor=round, num_cycles=num_cycles) distribution_timer(betavariate, 3.0, 3.0, post_processor=round, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.paretovariate, 4.0, post_processor=_math.floor, num_cycles=num_cycles) distribution_timer(paretovariate, 4.0, post_processor=_math.floor, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.gauss, 1.0, 1.0, post_processor=round, num_cycles=num_cycles) distribution_timer(gauss, 1.0, 1.0, post_processor=round, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.normalvariate, 0.0, 2.8, post_processor=round, num_cycles=num_cycles) distribution_timer(normalvariate, 0.0, 2.8, post_processor=round, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.lognormvariate, 0.0, 0.5, post_processor=round, num_cycles=num_cycles) distribution_timer(lognormvariate, 0.0, 0.5, post_processor=round, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.vonmisesvariate, 0, 0, post_processor=_math.floor, num_cycles=num_cycles) distribution_timer(vonmisesvariate, 0, 0, post_processor=_math.floor, num_cycles=num_cycles) print("Base Case") distribution_timer(_random.triangular, 0.0, 10.0, 0.0, post_processor=_math.floor, num_cycles=num_cycles) distribution_timer(triangular, 0.0, 10.0, 0.0, post_processor=_math.floor, num_cycles=num_cycles) some_list = [i for i in range(10)] print("Base Case") distribution_timer(_random.choice, some_list, num_cycles=num_cycles) distribution_timer(choice, some_list, num_cycles=num_cycles) weights = [i for i in reversed(range(1, 11))] sample_size = 1 print("Base Case") distribution_timer(_random.choices, some_list, weights, k=sample_size, num_cycles=num_cycles) distribution_timer(choices, some_list, weights, k=sample_size, num_cycles=num_cycles) cum_weights = list(_itertools.accumulate(weights)) print("Base Case") distribution_timer(_random.choices, some_list, cum_weights=cum_weights, k=sample_size, num_cycles=num_cycles) distribution_timer(choices, some_list, cum_weights=cum_weights, k=sample_size, num_cycles=num_cycles) print("Base Case") print(f"Timer only: random.shuffle(some_list) of size {len(some_list)}:") timer(_random.shuffle, some_list, cycles=8) print() print(f"Timer only: shuffle(some_list) of size {len(some_list)}:") timer(shuffle, some_list, cycles=8) print() print("Base Case") distribution_timer(_random.sample, some_list, k=3, num_cycles=num_cycles) distribution_timer(sample, some_list, k=3, num_cycles=num_cycles) stop_test = _time.time() print(f"\nTotal Test Time: {round(stop_test - start_test, 3)} sec")
""" Assignment 9 Import the random module and design a dice function. The dice function should take two arguments, one for the number of rolls and one for the size or number of sides of the dice. The function should simulate rolling the dice and finally return the sum of all the rolls. When this file is imported it should only add the dice function to the target namespace. However, when this file is run from the terminal it should also do the following: Print the result of rolling eight six sided dice (8d6). Format the result as if this was the damage dealt by a fireball spell in an RPG. Or come up with your own creative usage of the dice function. Hint: You may need to search online for the following: __all__ if __name__ == "__main__" Prepare to defend you choice of import style. """ from Fortuna import random_value from MonkeyScope import distribution_timer from random import choice arr = ('Apple', 'Grapes', 'Orange', 'Cherry', 'Pear') distribution_timer(random_value, arr) distribution_timer(choice, arr)