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 random_comic(): '''Opens a random comic. Without internet, it cycles only through the comics the user already has. ''' if CONNECTED: num = _randrange(1, int(MOST_RECENT)) get_comic_by_num(str(num)) else: comics = get_comic_list() if len(comics) > 0: num = _randrange(0, len(comics) - 1) open_image(comics[num]) else: print('You don\'t have any comics on you,', end=' ') print('nor are you connected to the internet...')
def atualizar_canos(): canos = _.canos for i, (x, y) in enumerate(canos): x -= 1 if x < -80: xmax = max(x for (x, _) in _.canos) x += xmax + 160 y = _randrange(-100, 0, 10) canos[i] = (x, y)
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 reiniciar(): """ Reinicia as variáveis de estado que controlam o jogo. """ _.ativo = False _.morto = False _.flappy_x = _.largura_tela // 3 _.flappy_y = _.altura_tela // 2 _.velocidade = 0 _.canos = [((i * 80) + _.largura_tela, _randrange(-100, 0, 10)) for i in range(4)] _.score = 0
def select_model(self, **kwargs): ''' Select a model to serve Returns -------- model_name : str The model identifier that is going to be served ''' r = _random() if r > self.epsilon: # exploitation max_value = max(self._values) # Randomly pick among those that have highest value indices = [i for i, x in enumerate(self._values) if x == max_value] r1 = _randrange(0, len(indices)) return_index = indices[r1] else: # exploration return_index = _randrange(len(self._values)) self._serve_counts[return_index] += 1 return self._models[return_index]
def select_model(self, **kwargs): ''' Select a model to serve Returns ------- model_name : str The model identifier that is going to be served ''' r = _random() if r > self.epsilon: # exploitation max_value = max(self._values) # Randomly pick among those that have highest value indices = [i for i, x in enumerate(self._values) if x == max_value] r1 = _randrange(0, len(indices)) return_index = indices[r1] else: # exploration return_index = _randrange(len(self._values)) self._serve_counts[return_index] += 1 return self._models[return_index]
def random_line(in_file): '''Given a file, returns a random line.''' in_file.seek(0, 2) # Initial seek. (for python 2 compatibility below) pos = _randrange(0, in_file.tell()) # Find a random position. in_file.seek(lseek(in_file, pos)) # Seek to the start of its line. return in_file.readline()
def random_ecosystem(self, dim): '''Creates a random configuration of the cells.''' func = lambda: True if _randrange(1, 12) == 1 else False return self.forge_ecosystem(dim, func)
def shuffle(self,rp=False): k = _dc(self) [_shuffle(k) for i in lzint(_randrange(100))] if rp: super().__init__(_dc(k)) return lzlist(k)
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)])