Example #1
1
def random_generator(num_vals, n_points_only=False):
    """outputs a random generator of len(lst) = num_vals"""
    start_list = random_list(num_vals)
    if n_points_only:
        gen_str = "n_points"
    else:
        gen_str = random.choice(["one_point", "random_point", "n_points"])
    if gen_str == "one_point":
        loc = random.choice(["start", "mid", "end"])
        generator = gen_one_point(start_list, loc)
        out_str = "%s\n%s at %s" % (start_list, gen_str, loc)
    elif gen_str == "random_point":
        generator = gen_random_point(start_list)
        out_str = "%s\n%s" % (start_list, gen_str)
    else:
        min_pts = len(start_list) // 10
        max_pts = len(start_list) // 5
        if min_pts < 1:
            min_pts = 1
        if max_pts < 2:
            max_pts = 2
        num_points = random.randrange(min_pts, max_pts + 1)
        generator = gen_n_points(start_list, num_points)
        out_str = "%s\n%s n=%s" % (start_list, gen_str, num_points)
    return generator, out_str
Example #2
0
        def heli_transport_flight(countries, airports: List[dcs.terrain.Airport]):
            country_str = countries[random.randrange(0, len(countries))]
            country = self.m.country(country_str)

            transports = [x for x in country.helicopters
                          if x.task_default == dcs.task.Transport]
            htype = random.choice(transports)

            start_airport = random.choice(airports)
            rand = random.random()
            name = "Helicopter Transport " + str(c_count)
            if 0.7 < rand:
                bound = dcs.mapping.Rectangle.from_point(start_airport.position, 100*1000)
                pos = bound.random_point()
                hg = self.m.flight_group_inflight(country, name, htype, pos, random.randrange(800, 1500, 100), 200)
                hg.add_runway_waypoint(start_airport)
                hg.land_at(start_airport)
            elif 0.4 < rand < 0.7:
                hg = self.m.flight_group_from_airport(country, name, htype, start_airport)
                hg.uncontrolled = True
            else:
                dest_airport = None
                while True:
                    dest_airport = airports[random.randrange(0, len(airports))]
                    if dest_airport != start_airport:
                        break

                hg = self.m.flight_group_from_airport(
                    country, name, htype, start_airport, start_type=random.choice(list(dcs.mission.StartType))
                )
                hg.add_runway_waypoint(start_airport)
                hg.add_runway_waypoint(dest_airport)
                hg.land_at(dest_airport)
            return hg
Example #3
0
def choose(buttons, data, algorithm, threshold = .10):
	"""
	takes as input an iterable of button types and input data. Currently the data will be passed in the form of 
	a dictionary with button names as keys and boolean lists from a bernoulli distribution as
	values. Optionally, set the threshold for the espilon first algorithm.
	For ucb1 returns a list of length three with name, best_true_mean, and confidence_bound.
	For epsilon first returns a list of length two with name and current expected mean
	"""
	# Exploration
	rand = random()
	if (rand < threshold) and (algorithm != 'ucb1'):
		# if we decided to explore, choose a button at random
		r_choice = choice(buttons)
		# determing the reward for the choice and update reward
		r_choice.reward_count += choice(data[r_choice.name])
		r_choice.trial_count += 1
		return [r_choice, r_choice.reward_count/r_choice.trial_count]
	# if we're not in ucb1 and we're not exploring, find the max expected mean
	expected_list = []
	for i in range(len(buttons)):
		if algorithm == 'ucb1':
			confidence_bound = math.sqrt(2*math.log(buttons[i].big_n)/buttons[i].trial_count)
			best_true_mean = (buttons[i].reward_count/buttons[i].trial_count) + confidence_bound
			# update the expected list
			expected_list.append([buttons[i], best_true_mean, confidence_bound])
			buttons[i].big_n += 1
			#print buttons[i], buttons[i].big_n, buttons[i].name
		else:
			# calculate expected mean and update to expected list
			expected_list.append([buttons[i],buttons[i].reward_count/buttons[i].trial_count])
	# get maximum expected value (adjusted with conf. bound for ucb1)
	winner = max(expected_list, key = lambda x: x[1])
	# update the reward and trial counts
	winner[0].get_reward(choice(data[winner[0].name]))
	return winner 
    def make_text(self, dictionary):
        """Takes dictionary of markov chains; returns random text."""

        capital_keys_list = [key for key in dictionary.keys() if key[0][0].isupper()]   # create list of only keys that start with an uppercase letter
        starting_key = random.choice(capital_keys_list)             # choose key (tuple) to start at
        new_text_string = " ".join(starting_key)           # add items in that tuple to string of created text
        limit = 140

        punctuation = "?.!"                                         # create punctuation string    

        while dictionary.get(starting_key) != None and len(new_text_string) < limit:             # Continue until the key is not found in the dictionary or until the limit is hit
            value_list = dictionary[starting_key]               # assign value of key (list)
            next_word = random.choice(value_list)               # choose random word w/in list
            new_text_string = new_text_string + " " + next_word     # add next_word to list of created text
            starting_key = tuple(list(starting_key[1:]) + [next_word])   # create new tuple from second word of previous tuple + item at that index
            #print "at start of while loop:", new_text_string

            while len(new_text_string) > limit:        # if length of the current string is greater than the limit, iterate through each character from the end to find punctuation
                # print "if block initiated", len(new_text_string), new_text_string
                for i in range(len(new_text_string)-2,-1,-1):
                    # print "checking next character", len(new_text_string)
                    if new_text_string[i] in punctuation:
                        new_text_string = new_text_string[0:(i+1)] # cut off string at punctuation
                        print "after cutting at punct:", len(new_text_string)
                        if len(new_text_string) <= limit:
                            return new_text_string
                else:                                           # if no punctuation was found:
                    new_text_string = new_text_string[:limit]   # chop off after 140 characters

        return new_text_string                                  # return new text
Example #5
0
 def download_shares():
     while True:
         desired = yield self.node.desired_var.get_when_satisfies(lambda val: len(val) != 0)
         peer_addr, share_hash = random.choice(desired)
         
         if len(self.peers) == 0:
             yield deferral.sleep(1)
             continue
         peer = random.choice(self.peers.values())
         
         print 'Requesting parent share %s from %s' % (p2pool_data.format_hash(share_hash), '%s:%i' % peer.addr)
         try:
             shares = yield peer.get_shares(
                 hashes=[share_hash],
                 parents=random.randrange(500), # randomize parents so that we eventually get past a too large block of shares
                 stops=list(set(self.node.tracker.heads) | set(
                     self.node.tracker.get_nth_parent_hash(head, min(max(0, self.node.tracker.get_height_and_last(head)[0] - 1), 10)) for head in self.node.tracker.heads
                 ))[:100],
             )
         except defer.TimeoutError:
             print 'Share request timed out!'
             continue
         except:
             log.err(None, 'in download_shares:')
             continue
         
         if not shares:
             yield deferral.sleep(1) # sleep so we don't keep rerequesting the same share nobody has
             continue
         self.handle_shares([(share, []) for share in shares], peer)
Example #6
0
def random_note():
    note = random.choice("abcdefg")
    acc = random.choice(["", "-", "--", "#", "##"])
    articulation = random.choice("n/otTS$RuHh;QpU[]_(){}\'s\\`~^vz,mwMW")
    duration = random.choice(["2", "4", "8", "16", "32", "64"])
    dot = random.choice(["", ".", ".."])
    return duration + dot + note + acc + articulation
Example #7
0
def get_npc_name(npc_dict, race, gender):
    race = race.lower()
    gender = gender.lower()
    names = npc_dict["{}_names".format(race)]
    preffixes = []
    intermediate = []
    suffixes = []
    if gender is "male" or gender is "m":
        gender = "m"
    else:
        gender = "f"
    for value_lists in names:
        if value_lists[0] == "{}pre".format(gender):
            preffixes.append(value_lists[1])
        else:
            preffixes.append(value_lists[1])
        if "{}suf".format(gender) == value_lists[0]:
            suffixes.append(value_lists[1])
        else:
            suffixes.append(value_lists[1])
        if "{}in".format(gender) == value_lists[0]:
            intermediate.append(value_lists[1])
        else:
            intermediate.append("")
    return rd.choice(preffixes) + rd.choice(intermediate) + rd.choice(suffixes)
Example #8
0
    def test_insert_list(self):
        db = yield tnt.Connection(tnt_host, tnt_port, reconnect=False)
        data = (
            (
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
                randint(0, 2 ** 32 - 1),
                long(randint(0, 2 ** 64 - 1)),
            ),
            (
                randint(0, 2 ** 32 - 1),
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
                long(randint(0, 2 ** 64 - 1)),
            ),
            (
                long(randint(0, 2 ** 64 - 1)),
                randint(0, 2 ** 32 - 1),
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
            ),
        )

        defer_list = []
        for t in data:
            r = db.insert(space_no0, *t)
            defer_list.append(r)

        result = yield defer.DeferredList(defer_list)
        for status, r in result:
            self.assertTrue(status)
            self.assertEqual(len(r), 0)
            self.assertIn(" inserted", repr(r))

        yield db.disconnect()
def addChemotaxis(CompuCell3DElmnt, config):
  PluginElmnt_4=CompuCell3DElmnt.ElementCC3D("Plugin",{"Name":"Chemotaxis"})
  # Select chemical field?
  ChemicalFieldElmnt=PluginElmnt_4.ElementCC3D("ChemicalField",{"Name":"FDS","Source":"DiffusionSolverFE"})
    
  # Define chemotaxis for cell type
  # TODO: iterate over cell types
  addedChemo = False
  for cell in range(1, config["numCellTypes"] + 1):
    if random.choice([True, False]):
      addedChemo = True
      ChemicalFieldElmnt.ElementCC3D("ChemotaxisByType",{"Lambda":getChemotaxisLambda(),"Type":str(cell)})
    elif cell == config["numCellTypes"] and addedChemo == False:
      # Always add chemotaxis for at least one cell type
      ChemicalFieldElmnt.ElementCC3D("ChemotaxisByType",{"Lambda":getChemotaxisLambda(),"Type":"1"})

    
  # Define chemical field
  SteppableElmnt=CompuCell3DElmnt.ElementCC3D("Steppable",{"Type":"DiffusionSolverFE"})
  DiffusionFieldElmnt=SteppableElmnt.ElementCC3D("DiffusionField",{"Name":"FDS"})
  DiffusionDataElmnt=DiffusionFieldElmnt.ElementCC3D("DiffusionData")
  DiffusionDataElmnt.ElementCC3D("FieldName",{},"FDS")
  DiffusionDataElmnt.ElementCC3D("GlobalDiffusionConstant",{},randomFloatStr(0, 1.0))
  DiffusionDataElmnt.ElementCC3D("GlobalDecayConstant",{},randomFloatStr(0, 1.0))
  
  secretionDataElement = DiffusionFieldElmnt.ElementCC3D("SecretionData")
  addedSecretion = False
  for cell in range(1, config["numCellTypes"] + 1):
    if random.choice([True, False]):
      addedSecretion = True
      secretionDataElement.ElementCC3D("Secretion", {"Type":str(cell)}, randomFloatStr(0.0, 100))
    elif cell == config["numCellTypes"] and addedSecretion == False:
      # Always add secretion for at least one cell type
      secretionDataElement.ElementCC3D("Secretion", {"Type":"1"}, randomFloatStr(0.0, 100))
def window_seg(floors, is_door=True):
    """Randomly generated window segment of tower.
    """
    windowed = BEAM + (random.choice([' ', WINDOW]) if is_door else HI_BEAM)
    for _ in range(1, floors):
        windowed += BLANK + random.choice([' ', WINDOW])
    return windowed + BEAM
Example #11
0
    def handle(self, *args, **options):
        users = list(User.objects.all())

        for i in range(10):
            t = Topic()
            t.name = u'Topic Name {}'.format(i)
            t.description = u'Topic Description {}'.format(i)
            t.save()
        topics = list(Topic.objects.all())

        for j in range(100):
            q = Question()
            q.author = random.choice(users)
            q.title = u'title {}'.format(j)
            q.text = u'text {}'.format(j)
            q.pub_date = datetime.datetime.now()
            q.is_published = True
            q.save()
            q.topics = random.sample(topics, random.randint(1, 6))
        questions = list(Question.objects.all())

        for k in range(100):
            c = Comment()
            c.author = random.choice(users)
            c.question = random.choice(questions)
            c.text = u'text {}'.format(k)
            c.pub_date = datetime.datetime.now()
            c.save()
Example #12
0
def generate(data):
    m = random.choice([3, 1.4, 1.6, 1.8])
    h = random.choice([4, 12, 14, 16])
    d = 1.5*h
    g = 9.8 
    v0xmin = d*math.sqrt(g/(2*h))
    v0x = round(random.choice([4, v0xmin*1.4, v0xmin*1.6, v0xmin*1.8]), 3)

    data["params"]["m"] = m
    data["params"]["h"] = h
    data["params"]["d"] = d
    data["params"]["v0x"] = v0x

    t = d/v0x

    data["params"]["t_c"] = round(t, 3)
    data["params"]["t_x1"] = round(math.sqrt(2*h/g), 3)
    data["params"]["t_x2"] = round(v0x*2/g, 3)

    v0y = 0.5*g*t - h/t

    data["params"]["vy_c"] = round(v0y, 2)
    data["params"]["vy_x1"] = round(-math.sqrt((g*t)**2 + v0x**2/2), 2)
    data["params"]["vy_x2"] = round( -0.5*g*t - h/2, 2)
    data["params"]["vy_x3"] = round(-math.sqrt(v0x**2 + v0y**2), 2)
    data["params"]["vy_x4"] = 0
Example #13
0
    def __init__(self, alphabet=['A', 'B', 'C'], motifs=['ABC'], m=0.2, size=100):
        """Generate a new random sequence.

        Parameters:
            - alphabet: a list of letters
            - motifs  : a list of strings
            - m       : probability of starting a motif at a random position
                        of the sequence
            - size    : length of the sequence
        """
        self.alphabet = set(alphabet)
        for motif in motifs:
            self.alphabet = self.alphabet.union(motif)
        self.alphabet = list(self.alphabet)
        self.motifs = motifs
        # Motif average length
        L = sum(len(motif) for motif in motifs)/float(len(motifs))
        p = m*L  # threshold to insert a new motif
        s = ''   # random string
        n = 0    # string length
        while n < size:
            motif = random.choice(motifs)
            w = len(motif)
            if random.random() <= p:
                s += motif
            else:
                for i in xrange(w):
                    s += random.choice(self.alphabet)
            n += w
        super(TestSequence, self).__init__(s[:size])
Example #14
0
    def test_random(self):
        import random
        d = {}  # mirror the database
        for dummy in range(5):
            f = dumbdbm.open(_fname)
            for dummy in range(100):
                k = random.choice('abcdefghijklm')
                if random.random() < 0.2:
                    if k in d:
                        del d[k]
                        del f[k]
                else:
                    v = random.choice('abc') * random.randrange(10000)
                    d[k] = v
                    f[k] = v
                    self.assertEqual(f[k], v)
            f.close()

            f = dumbdbm.open(_fname)
            expected = d.items()
            expected.sort()
            got = f.items()
            got.sort()
            self.assertEqual(expected, got)
            f.close()
Example #15
0
    def test_insert(self):
        db = yield tnt.Connection(tnt_host, tnt_port, reconnect=False)
        data = (
            (
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
                randint(0, 2 ** 32 - 1),
                long(randint(0, 2 ** 64 - 1)),
            ),
            (
                randint(0, 2 ** 32 - 1),
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
                long(randint(0, 2 ** 64 - 1)),
            ),
            (
                long(randint(0, 2 ** 64 - 1)),
                randint(0, 2 ** 32 - 1),
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
            ),
        )

        for t in data:
            r = yield db.insert(space_no0, *t)
            self.assertEqual(len(r), 0)
            self.assertIn(" inserted", repr(r))

        yield db.disconnect()
Example #16
0
def encode(f):
    var_name = ''.join(
        random.choice(string.ascii_lowercase + string.ascii_uppercase)
        for i in range(50))
    if _version is 2:
        rev_data = binascii.b2a_base64(f)[-2::-1]
        data = var_name + ' = "' + str(rev_data) + '"'
    if _version is 3:
        rev_data = binascii.b2a_base64(f.encode('utf8')).decode('utf8')[-2::-1]
        data = var_name + ' = "' + str(rev_data) + '"'

    func_name = ''.join(
        random.choice(string.ascii_lowercase + string.ascii_uppercase)
        for i in range(50))
    func_argv = ''.join(
        random.choice(string.ascii_lowercase + string.ascii_uppercase)
        for i in range(50))
    f = '''
import binascii
import sys
%s
def %s(%s):
    if sys.version_info.major is 2:
        return str(binascii.a2b_base64(%s[::-1]))
    elif sys.version_info.major is 3:
        return str(binascii.a2b_base64(%s[::-1]).encode('utf8'))[::-1].decode('utf8')
    else:
        sys.exit('Your python version is not supported!')
exec(%s(%s))
''' % (data, func_name, func_argv, func_argv, func_argv,
       func_name, var_name)
    return f
Example #17
0
    def test_call(self):
        db = yield tnt.Connection(tnt_host, tnt_port, reconnect=False)
        data = (
            (
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
                randint(0, 2 ** 32 - 1),
                long(randint(0, 2 ** 64 - 1)),
            ),
            (
                randint(0, 2 ** 32 - 1),
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
                long(randint(0, 2 ** 64 - 1)),
            ),
            (
                long(randint(0, 2 ** 64 - 1)),
                randint(0, 2 ** 32 - 1),
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
            ),
        )

        for t in data:
            r = yield db.call("box.insert", tuple(type(x) for x in t), str(space_no0), *t)
            self.assertEqual(len(r), 1)
            self.assertEqual(t, r[0])

        for t in data:
            r = yield db.call("box.select", tuple(type(x) for x in t), str(space_no0), "0", t[0])
            self.assertEqual(len(r), 1)
            self.assertEqual(t, r[0])

        yield db.disconnect()
Example #18
0
def ss():
    families = []
    mapping = {}

    with open('easy-248.txt') as f:
        for line in f.readlines():
            families.append(line.split())

    families.sort(key = lambda x: -len(x))
    recip = []
    for family in families:
        recip.append(family[:])

    for (i, family) in enumerate(families):
        for person in family:
            # select a family
            other_families = list(range(len(recip)))
            other_families.remove(i)
            random_family = random.choice(other_families)
            fail_count = 0
            while len(recip[random_family]) == 0:
                if fail_count > len(families):
                    return {}
                random_family = random.choice(other_families)
            # select a member within that family
            random_member = random.choice(recip[random_family])

            mapping[person] = random_member
            # remove from recip list
            recip[random_family].remove(random_member)
    return mapping
Example #19
0
def get_npc_belongings(npc_dict, level, npc_class):
    level = int(level)
    npc_belongings_value = int(level) * 100 * rd.gauss(1,0.5)
    weapons = []
    armors = []
    belongings = ""

    try:
        assert npc_belongings_value >= 0
        for i in range(int(level / 5) + 1):
            choose_weapon = rd.choice(npc_dict["weapon"])
            choose_armor = rd.choice(npc_dict["armor"])
            weapons.append(choose_weapon[0])
            armors.append(choose_armor[0])
            npc_belongings_value -= (int(choose_weapon[1]) + int(choose_armor[1]))
    except AssertionError:
        for armor in armors:
            belongings += armor + ", "
        belongings = belongings[:-2] + "\n"
        for weapon in weapons:
            belongings += weapon + ", "
        return belongings

    for armor in armors:
        belongings += armor + ", "
    belongings = belongings[:-2] + "\n"
    for weapon in weapons:
        belongings += weapon + ", "
    belongings = belongings[:-2] + "\n"
    while npc_belongings_value > 0:
        chosen_item = rd.choice(npc_dict["other"])
        belongings += chosen_item[0] + ", "
        npc_belongings_value -= int(chosen_item[1])
    belongings = belongings[:-2] + "\n"
    return get_npc_ac(armors, npc_class), belongings
Example #20
0
 def next_task(self, channel):
     if self.state == TaskManager.START:
         self.map_iter = iter(self.datasource)
         self.working_maps = {}
         self.map_results = {}
         #self.waiting_for_maps = []
         self.state = TaskManager.MAPPING
     if self.state == TaskManager.MAPPING:
         try:
             map_key = self.map_iter.next()
             map_item = map_key, self.datasource[map_key]
             self.working_maps[map_item[0]] = map_item[1]
             return ('map', map_item)
         except StopIteration:
             if len(self.working_maps) > 0:
                 key = random.choice(self.working_maps.keys())
                 return ('map', (key, self.working_maps[key]))
             self.state = TaskManager.REDUCING
             self.reduce_iter = self.map_results.iteritems()
             self.working_reduces = {}
             self.results = {}
     if self.state == TaskManager.REDUCING:
         try:
             reduce_item = self.reduce_iter.next()
             self.working_reduces[reduce_item[0]] = reduce_item[1]
             return ('reduce', reduce_item)
         except StopIteration:
             if len(self.working_reduces) > 0:
                 key = random.choice(self.working_reduces.keys())
                 return ('reduce', (key, self.working_reduces[key]))
             self.state = TaskManager.FINISHED
     if self.state == TaskManager.FINISHED:
         self.server.handle_close()
         return ('disconnect', None)
 def __init__(self, game, where= 0, adjective="", description="",
      boss=False, carrier=False):
     self.number = Monster.number
     Monster.number += 1
     game.monsters[self.number] = self # add monster into game dict
     self.adjective = adjective
     self.location = where # room number
     self.description = description
     self.hitpoints = random.randint(5,15)
     self.player = False
     self.carrier = carrier # can carry items ?
     self.attack = 10 + random.randint(-2,2)
     self.defense = 10 + random.randint(-2,2)
     self.speed = 10 + random.randint(-2,2)
     self.damage = 3 + random.randint(-2,2)
     self.armor = 3 + random.randint(-2,2)
     self.agressive = False
     self.slots = {"head":1, "body":1, "hand":2, "finger":2,
                   "neck":1, "feet":2} # only one magic ring per ring-finger
     if description == "":
         if boss:
             self.adjective = random.choice(("deadly","fantastic",
                     "creepy","ugly","epic"))
             self.description = random.choice(("dragon","cave drake",
                     "sea serpent","gorgon","giant beetle","arch druid"))
             self.hitpoints *= 5
             self.attack += random.randint(2,7)
             self.defense += random.randint(2,7)
             self.speed += random.randint(2,7)
         else:
             self.adjective = random.choice(("weak","boring",
                     "tired","cheap","old"))
             self.description = random.choice(("goblin","ork","troll",
                 "mice","rat","dwarf","spider"))
Example #22
0
    def reset_password(self, user):
        if not user:
            return { 'status': 'error', 'message': "You must pass a user to reset a password", 'data': None }

        if user.has_key('status'):
            if user['status'] == 'ok':
                user = user['data']
            else:
                return user
        
        # generate random password
        password = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(8))

        # crypt password
        cpassword = crypt.crypt(password, ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(2)))

        # update the user entry in the DB
        self.users_db.execute("UPDATE users SET password=? WHERE login=?", (cpassword, user['login'], ))

        # send the user a mail with the new password
        email = user['email']
        messageSubject = "anvio password reset"
        messageText = "You have requested your password for your anvi'o account to be reset.\n\nYour new password is:\n\n"+password+"\n\nPlease log into anvi'o with these credentials and change your password.";

        self.mailer.send(email, messageSubject, messageText)

        return { 'status': 'ok', 'message': "User password reset, message sent to %s" % email, 'data': None }
Example #23
0
 async def _top_(self, *, content : str):
     """Make a retrosign with top and middle text"""
     texts = [t.strip() for t in content.split(';')]
     if len(texts) != 2:
         await self.bot.say("\N{CROSS MARK} please provide two words seperated by ';'")
         return
     else:
         data = dict(
           bcg=choice([1, 2, 3, 4, 5]),
           txt=choice([1, 2, 3, 4]),
           text1=texts[0],
           text2=texts[1],
           text3=""
         )
         await self.bot.type() 
         with aiohttp.ClientSession() as session:
           async with session.post("http://photofunia.com/effects/retro-wave", data=data) as response:
             if response.status == 200:
               soup = b_s(await response.text(), "lxml")
               download_url = soup.find("div", class_="downloads-container").ul.li.a["href"]
               async with session.get(download_url) as image_response:
                 if image_response.status == 200:
                   image_data = await image_response.read()
                   with BytesIO(image_data) as temp_image:
                     await self.bot.upload(temp_image, filename="retro.jpg")
def genQuarters(main_cells):
    quarter_cells = []
    prev_note = -3
    pre_prev_note = -2
    for main_cell in main_cells:
        main_pits = [i[0] for i in main_cell.beat_pits]
        if len(main_pits) == 1:
            main_pits.append(None) #we have a "Free" note
        if main_cell.chord == None or main_cell.chord == []:
            quarter_cells.append(gc.genBlankCell(2.0))
        else:
            pits = []
            for main_pit in main_pits:
                if main_pit == None:
                    if pre_prev_note == prev_note:
                        pits.append(sc.closestNoteDegreeInChord(prev_note + random.choice([-2,2]), main_cell.chord))
                    else:
                        pits.append(sc.closestNoteDegreeInChord(prev_note, main_cell.chord))
                else:
                    closest_chord_notes = sc.closestNotesInChord(prev_note + random.choice([-2,2]), main_cell.chord)
                    closest_chord_notes = filter(lambda i: i > -7, closest_chord_notes)
                    for chord_note in closest_chord_notes:
                        if hm.matches(chord_note, main_pit):
                            pits.append(chord_note)
                            break
                pre_prev_note = prev_note
                prev_note = pits[-1]
            durs = [1.0,1.0]
            quarter_cells.append(Chunk(pits=pits, durs=durs, chord=main_cell.chord, key = main_cell.key))
        prev_note = quarter_cells[-1].pits[-1]
    return quarter_cells
	def randomMoves(self):
		# Spazz out for 12 seconds, making random move every 3 seconds
		for x in range(1,5): #running 4 times
			dirX = random.choice([0,1,2])
			dirY = random.choice([0,2]) #not using 1 as it would just turn wheels
			speed = random.randint(5,10)
			self.moveXY(dirX,dirY,speed,3)
Example #26
0
File: main.py Project: mansxu/2048
	def spawn_number(self, *args):
		empty = list(self.iterate_empty())
		if not empty:
			return
		value = choice([2]*9+[4])
		ix, iy = choice(empty)
		self.spawn_number_at(ix, iy, value)
Example #27
0
def gen_insult(user):
    adj = [
        "acidic", "antique", "contemptible", "culturally-unsound", "despicable", "evil", "fermented", "festering", "foul", "fulminating", "humid",
        "impure", "inept", "inferior", "industrial", "left-over", "low-quality", "malodorous", "off-color", "penguin-molesting", "petrified",
        "pointy-nosed", "salty", "sausage-snorfling", "tastless", "tempestuous", "tepid", "tofu-nibbling", "unintelligent", "unoriginal",
        "uninspiring", "weasel-smelling", "wretched", "spam-sucking", "egg-sucking", "decayed", "halfbaked", "infected", "squishy", "porous",
        "pickled", "coughed-up", "thick", "vapid", "hacked-up", "unmuzzleld", "bawdy", "vain", "lumpish", "churlish", "fobbing", "rank", "craven",
        "puking", "jarring", "fly-bitten", "pox-marked", "fen-sucked", "spongy", "droning", "gleeking", "warped", "currish", "milk-livered", "surly",
        "mammering", "ill-borne", "beef-witted", "tickle-brained", "half-faced", "headless", "wayward", "rump-fed", "onion-eyed", "beslubbering",
        "villainous", "lewd-minded", "cockered", "full-gorged", "rude-snouted", "crook-pated", "pribbling", "dread-bolted", "fool-born", "puny",
        "fawning", "sheep-biting", "dankish", "goatish", "weather-bitten", "knotty-pated", "malt-wormy", "saucyspleened", "motley-mind", "it-fowling",
        "vassal-willed", "loggerheaded", "clapper-clawed", "frothy", "ruttish", "clouted", "common-kissing", "pignutted", "folly-fallen",
        "plume-plucked", "flap-mouthed", "swag-bellied", "dizzy-eyed", "gorbellied", "weedy", "reeky", "measled", "spur-galled", "mangled",
        "impertinent", "bootless", "toad-spotted", "hasty-witted", "horn-beat", "yeasty", "boil-brained", "tottering", "hedge-born",
        "hugger-muggered", "elf-skinned"
    ]
    amt = [
        "accumulation", "bucket", "coagulation", "enema-bucketful", "gob", "half-mouthful", "heap", "mass", "mound", "petrification", "pile",
        "puddle", "stack", "thimbleful", "tongueful", "ooze", "quart", "bag", "plate", "ass-full", "assload"
    ]
    noun = [
        "bat toenails", "bug spit", "cat hair", "chicken piss", "dog vomit", "dung", "fat-woman's stomach-bile", "fish heads", "guano", "gunk",
        "pond scum", "rat retch", "red dye number-9", "Sun IPC manuals", "waffle-house grits", "yoo-hoo", "dog balls", "seagull puke", "cat bladders",
        "pus", "urine samples", "squirrel guts", "snake assholes", "snake bait", "buzzard gizzards", "cat-hair-balls", "rat-farts", "pods",
        "armadillo snouts", "entrails", "snake snot", "eel ooze", "slurpee-backwash", "toxic waste", "Stimpy-drool", "poopy", "poop",
        "craptacular carpet droppings", "jizzum", "cold sores", "anal warts"
    ]
    msg = '%s is a %s %s of %s.' % (user, choice(adj), choice(amt), choice(noun))
    return msg
Example #28
0
    def test_insert_ret_list(self):
        db = yield tnt.Connection(tnt_host, tnt_port, reconnect=False)
        data = (
            (
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
                randint(0, 2 ** 32 - 1),
                long(randint(0, 2 ** 64 - 1)),
            ),
            (
                randint(0, 2 ** 32 - 1),
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
                long(randint(0, 2 ** 64 - 1)),
            ),
            (
                long(randint(0, 2 ** 64 - 1)),
                randint(0, 2 ** 32 - 1),
                ''.join(choice(insert_string_choice) for x in xrange(randint(0, insert_string_length_max))),
            ),
        )

        defer_list = []
        for t in data:
            r = db.insert_ret(space_no0, tuple(type(x) for x in t), *t)
            defer_list.append(r)

        result = yield defer.DeferredList(defer_list)
        for i, r in enumerate(result):
            self.assertTrue(r[0])
            self.assertEqual(len(r[1]), 1)
            self.assertEqual(data[i], r[1][0])

        yield db.disconnect()
def comp_attack(computer):
	misses = []
	if computer.hits == []:
		while True:
			x = random.randint(0, 9)
			y = random.randint(0, 9)
			if (x, y) in computer.misses:
				continue
			elif (x, y) in computer.hits:
				continue
			else:
				return (x, y)
	else:
		while True:
			xy = random.choice(computer.hits)
			change = random.choice(((0, 1), (1, 0)))
			xy = update_coordinate(xy, change)
			if xy in computer.misses:
				misses.append(0)
			elif xy in computer.hits:
				misses.append(0)
			else:
				return xy
			if len(misses) >= 5:
				while True:
					x = random.randint(0, 9)
					y = random.randint(0, 9)
					if (x, y) in computer.misses:
						continue
					elif (x, y) in computer.hits:
						continue
					else:
						return (x, y)
    def corrupt(self):
        """
        Return a (notw2, weight), a corrupt target word and its weight.
        Note: This will return a different random value every call.
        """
        from hyperparameters import HYPERPARAMETERS
        import random
        possible_targets = targetmap()[self.w1][self.l2]
        assert len(possible_targets) > 1
        assert self.w2 in possible_targets
        notw2 = self.w2
        cnt = 0
        while self.w2 == notw2:
            if HYPERPARAMETERS["NGRAM_FOR_TRAINING_NOISE"] == 0:
                notw2 = random.choice(possible_targets)
                pr = 1./len(possible_targets)
            elif HYPERPARAMETERS["NGRAM_FOR_TRAINING_NOISE"] == 1:
                assert 0
    #            import noise
    #            from common.myrandom import weighted_sample
    #            e[-1], pr = weighted_sample(noise.indexed_weights())
    ##            from vocabulary import wordmap
    ##            print wordmap.str(e[-1]), pr
            else:
                assert 0
            cnt += 1
            # Backoff to 0gram smoothing if we fail 10 times to get noise.
            if cnt > 10: notw2 = random.choice(possible_targets)

        if HYPERPARAMETERS["UNIFORM EXAMPLE WEIGHTS"]:
            weight = 1.
        else:
            weight = 1./pr
        return notw2, weight