def spawn_coins(self): """ Spawns coins """ self.__objects["coins"] += Coins( \ np.array([config.WIDTH, \ util.randint(0, config.MAX_HEIGHT - 4)], dtype='float64'), np.array([3, util.randint(3, 10)])).get_items()
def get_required_adult_distributions(self): """ This function returns a dictionary of adult-children distributions (a numpy random distribution) for a ConnectionTypes and circle size. The returned data structure is a dictionary whose keys are ConnectionTypes. Each value is another dictionary relating circle size to the relevant random variable. The random distributions can return random variables (via dist.rvs()) that is the number of adults in the circle. """ all_students = 0 all_teachers = 0 for i in range(len(self.ages)): if self.ages[i] <= 18: all_students += self.age_prob[ i] * self.connection_type_prob_by_age_index[i][ ConnectionTypes.School] else: all_teachers += self.age_prob[ i] * self.connection_type_prob_by_age_index[i][ ConnectionTypes.Work] * self.teachers_workforce_ratio # teacher to student ratio is the part of the school-going population that are teachers. # it is used to calculate how many teachers are needed in each school (according to school size) if all_students > 0: teacher_to_student_ratio = all_teachers / all_students else: teacher_to_student_ratio = 1 school_sizes = self.circle_size_distribution_by_connection_type[ ConnectionTypes.School][0] family_sizes = self.circle_size_distribution_by_connection_type[ ConnectionTypes.Family][0] family_distributions = { size: randint(1, 2) for size in family_sizes if size == 1 } family_distributions.update({ size: rv_discrete(1, 2, values=([1, 2], [0.2, 0.8])) for size in family_sizes if size == 2 }) family_distributions.update({ size: rv_discrete(1, 3, values=([1, 2, 3], [0.1, 0.8, 0.1])) for size in family_sizes if size > 2 }) return { ConnectionTypes.School: { school_size: randint(round(school_size * teacher_to_student_ratio), round(school_size * teacher_to_student_ratio) + 1) for school_size in school_sizes }, ConnectionTypes.Family: family_distributions }
def ecdsa_sign(curve_obj, hash_int, hash_num_bits, private_key, message, k=None): """Sign message using the private key. Returns the signature (r, s). @param hash_int: a hash function mapping to an integer, for example lambda m: util.be2int(hashlib.sha256(m).digest()) @param hash_num_bits: the number of bits in the digest above, for example 256. """ n = curve_obj.order if k is None: k = util.randint(1, n - 1) e = hash_int(message) L_n = util.count_bits(n) z = e >> max(hash_num_bits - L_n, 0) while True: (x1, y1) = curve.mul(k, curve_obj.base_point, curve_obj.curve) r = x1 % curve_obj.order if r == 0: continue k_neg = numbertheory.inverse_of(k, n) s = (k_neg * (z + r * private_key)) % n if s == 0: continue break return (r, s)
def spawn_firebeam(self): """ Spawns a firebeam """ self.__objects["beams"].append(FireBeam( \ np.array([config.WIDTH, util.randint(0, config.MAX_HEIGHT - 6)], \ dtype='float64')))
def suggestword(self, word): query = {'callback': 'jQuery%s_%s' % (util.randint(20), util.timems()), 'q': word, 'dict': 'dict', 's': 'dict'} __data = util.get_url_html_string(self.SUGGEST, query) print __data return [i['g'] for i in util.jsonstrtodict(util.getjson(__data).replace(" ", " "))['s']]
def __init__(self, position, orientation=None): """ Constructor for FireBeam Args: position [px, py] : Initial position of the FireBeam orientation (int) : 0 -> config.FIREBEAM_MAX, type of FireBeam """ if orientation is None or orientation < 0 or orientation > config.FIREBEAM_MAX: orientation = util.randint(0, config.FIREBEAM_MAX - 1) rep = util.str_to_array(graphics.FIREBEAM[orientation]) color = util.tup_to_array(rep.shape, (col.Back.RED, col.Fore.YELLOW)) super().__init__(rep, position, np.array([-2., 0.]), util.mask(rep, color))
from common import * import util # one iteration X = np.array(R) X, X_test = util.train_test_split(X, train_size=0.9, random_state=util.randint()) #print X, X_test #create_matlab_input(X) #execute_matlab_code()
def test_random_correct_range(self): for i in xrange(10000): r = util.randint(1, 6) self.assertTrue(r in [1, 2, 3, 4, 5, 6])
def generate_private_key(self, seed): return 2**254 + 8 * util.randint(0, 2**251 - 1)
def generate_private_key(self, seed): return util.randint(1, self.order - 1)
def generate_private_key(self, seed): # As Curve25519 this one has a cofactor of 8. return 2**413 + 8 * util.randint(0, 2**410 - 1)