def __init__(self, key=None): from random import seed as _seed from time import time as _time from random import randrange as _randrange _seed(_time()) if key == None: self.key = ''.join(chr(_randrange(97,123)) for i in range(100)) elif not all(ord(i) in range(97,123) for i in key) or any(i.isdigit() for i in key): raise ValueError("Key must consist of lowercase alphabet characters") else: self.key = key
def mkrandlist(length,start=None,end=None): if not start and end: start=end end= None if not start: start=100 _k=lzlist([]) for i in lzint(length): _seed(_randrange(0,_randrange(10000000000))) if start and end: _k.append(_randrange(start,end)) else: _k.append(_randrange(start)) return _k
def scatter(shape, amount, seed): """Generate points within the boundaries of a shape.""" if shape is None: return None _seed(seed) bx, by, bw, bh = list(shape.bounds) points = [] for i in xrange(amount): tries = 100 while tries > 0: pt = Point(bx + uniform(0, 1) * bw, by + uniform(0, 1) * bh) if shape.contains(pt): points.append(pt) break tries -= 1 return points
def pack(shapes, iterations, padding, seed): _seed(seed) packed_objects = [] for path in shapes: packed_objects.append(PackObject(path)) for i in xrange(1, iterations): _pack(packed_objects, damping=0.1/i, padding=padding) geo = Geometry() for po in packed_objects: print po.x, po.y p = Transform.translated(po.x, po.y).map(po.path) geo.add(p) return geo
def obfuscate(s): '''\ Simple Obfuscation Utility Output: URURURURUR...UR where U stands for chars in the clear text, and R stands for chars randomly generated. ''' length = len(s) _seed() randrange = [chr(i) for i in range(0x20, 0x7f)] # Randomized chars tmp2 = [_choice(randrange) for i in range(length)] # Interpolate # This integer division is Python 2.x-specific, but since # Django hasn't supported Py3k yet, this shouldn't cause # problem in understanding return ''.join(s[i/2] if i%2==0 \ else tmp2[i/2] \ for i in range(length*2))
def angle_pack(shapes, seed, limit, maximum_radius, angle_tries=1, use_bounding_box=False): if shapes is None: return None _seed(seed) def center_and_translate(shape, tx=0, ty=0): bx, by, bw, bh = list(shape.bounds) t = Transform() t.translate(-bw / 2 - bx, -bh / 2 - by) return t.map(shape) geo = Geometry() bounding_path = Path() # Center first shape first_shape = center_and_translate(shapes[0]) geo.add(first_shape) bounding_path.cornerRect(first_shape.bounds) for shape in shapes[1:]: centered_shape = center_and_translate(shape) angles = [] for i in range(angle_tries): a = uniform(0, 360) if use_bounding_box: d = try_angle(bounding_path, centered_shape, a, limit, maximum_radius, use_bounding_box) else: d = try_angle(geo, centered_shape, a, limit, maximum_radius, use_bounding_box) angles.append([d, a]) chosen_distance, chosen_angle = sorted(angles)[0] tx, ty = coordinates(0, 0, chosen_distance, chosen_angle) t = Transform() t.translate(tx, ty) translated_shape = t.map(centered_shape) bounding_path.cornerRect(translated_shape.bounds) geo.add(translated_shape) return geo
def decorated_function(*args, **kwargs): seed = args[-1] _seed(seed) new_args = args[:-1] return fn(*new_args, **kwargs)
def _set_seed(seed=None): if seed is not None: _seed(seed)
def choice_words(phrase_book, root_key='root', seed=None): if isinstance(seed, int): seed = str(seed << 10) _seed(seed) return eval_phrase(phrase_book, lookup_phrase(root_key, phrase_book))
for i in range(ASTEROID_COUNT, ASTEROID_COUNT + RESOURCE_COUNT): # Resource index starts after the ASTEROID_COUNT game.add_widget(Resource(), i) # Adding i-th resource xpos = _randint(0, XSIZE) ypos = _randint(0, YSIZE) # Set the resource location game.children[i].pos = (xpos, ypos) # Set the resource location attributes, float game.children[i].pos_x = xpos game.children[i].pos_y = ypos # Set the resource velocity; float game.children[i].vel_x = MAX_RESOURCE_SPEED / (_randint(-3, 3) + 0.5) game.children[i].vel_y = MAX_RESOURCE_SPEED / (_randint(-3, 3) + 0.5) Clock.schedule_interval(game.update, TIME_STEP) return game if __name__ == '__main__': # Initialize the random generator _seed() # Set the window size; the way is ugly, but this is the best advice I've found Config.set('graphics', 'width', str(XSIZE)) Config.set('graphics', 'height', str(YSIZE)) # Launch the application RocketApp().run()
game.children[i].vel_y = MAX_ASTEROID_SPEED / (_randint(-3, 3) + 0.5) # Adding resources as next items on the widget list for i in range(ASTEROID_COUNT, ASTEROID_COUNT + RESOURCE_COUNT): # Resource index starts after the ASTEROID_COUNT game.add_widget(Resource(), i) # Adding i-th resource xpos = _randint(0, XSIZE) ypos = _randint(0, YSIZE) # Set the resource location game.children[i].pos = (xpos, ypos) # Set the resource location attributes, float game.children[i].pos_x = xpos game.children[i].pos_y = ypos # Set the resource velocity; float game.children[i].vel_x = MAX_RESOURCE_SPEED / (_randint(-3, 3) + 0.5) game.children[i].vel_y = MAX_RESOURCE_SPEED / (_randint(-3, 3) + 0.5) Clock.schedule_interval(game.update, TIME_STEP) return game if __name__ == '__main__': # Initialize the random generator _seed() # Set the window size; the way is ugly, but this is the best advice I've found Config.set('graphics', 'width', str(XSIZE)) Config.set('graphics', 'height', str(YSIZE)) # Launch the application RocketApp().run()
from copy import deepcopy as _dc import time from random import seed as _seed ,randrange as _randrange ,sample as _sample from random import shuffle as _shuffle, choice as _choice, choices as _choices from itertools import product as _product, permutations as _permutations from itertools import combinations as _combinations,combinations_with_replacement as _combinations_with_replacement from hashlib import sha512 as _sha512 from math import ceil as _mceil from string import ascii_letters as _ascii_chars, digits as _digs from re import search as _se, sub as _sub _seed(time.time()*_randrange(1234,123456789)) del time __all__ = ["lzlist","lzstr","lzdict","lzint","lzfloat"] __author__ = "Matthew Lam" __email__ = "*****@*****.**" __version__ = "1.0.1" __license__ = "MIT" class lzlist(list): def __init__(self, ip=[]): super().__init__(ip) self.__copy = ip def __hash__(self): _h = _sha512() [_h.update(str(i).encode("utf-32")) for i in self] return int(_h.hexdigest(),16) def includes_type(self,tp): return any([i for i in self if isinstance(i,tp)])