Last active
December 6, 2019 22:05
-
-
Save laginha/1254359 to your computer and use it in GitHub Desktop.
Interface built over python module random
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random, math | |
MAX = 100 | |
MIN = 10 | |
class Randomizer: | |
def __init__(self): | |
self.choice = random.choice | |
self.list = lambda f,m: [ f() for i in self.range(0,m) ] | |
self.hash = lambda a,b: dict( zip( a(), b() ) ) | |
self.comma_separated = lambda f,a: ','.join( f( a ) ) | |
def __generate(self, f): | |
for i in self.range(): | |
yield f() | |
def resize(self, l): | |
return [i for i in l if self.boolean()] | |
def range(self, mi=0, ma=MAX, s=1): | |
return range( mi, ma, s) | |
def number(self, mi=MIN, ma=MAX): | |
return random.randint( mi, ma ) | |
def char(self): | |
c = [ self.number(65, 90), self.number(97, 122) ] | |
return chr( self.choice( c ) ) | |
def char_number(self): | |
return chr( self.number(48,57) ) | |
def string(self, ma=MAX): | |
return ''.join( self.list_of_chars( ma ) ) | |
def boolean(self): | |
return self.number(0,1) == 1 | |
def text(self, ma=MAX): | |
return '\n'.join( self.list_of_strings( ma ) ) | |
def items(self): | |
return self.hash_of_chars().items() | |
def comma_separated_number(self, ma=MAX): | |
return self.comma_separated( self.list_of_char_numbers, ma ) | |
def comma_separated_char(self, ma=MAX): | |
return self.comma_separated( self.list_of_chars, ma ) | |
def comma_separated_string(self, ma=MAX): | |
return self.comma_separated( self.list_of_strings, ma ) | |
def list_of_char_numbers(self, ma=MAX): | |
return self.list( self.char_number, ma ) | |
def list_of_numbers(self, ma=MAX): | |
return self.list( self.number, ma ) | |
def list_of_chars(self, ma=MAX): | |
return self.list( self.char, ma ) | |
def list_of_strings(self, ma=MAX): | |
return self.list( self.string, ma ) | |
def list_of_hashes(self, ma=MAX): | |
return self.list( self.hash, ma ) | |
def list_of_booleans(self, ma=MAX): | |
return self.list( self.boolean, ma ) | |
def hash_of_numbers(self): | |
return self.hash( self.list_of_numbers, self.list_of_numbers ) | |
def hash_of_chars(self): | |
return self.hash( self.list_of_chars, self.list_of_chars ) | |
def hash_of_strings(self): | |
return self.hash( self.list_of_strings, self.list_of_strings ) | |
def generate_numbers(self): | |
return self.__generate( self.number ) | |
def generate_chars(self): | |
return self.__generate( self.char ) | |
def generate_strings(self): | |
return self.__generate( self.string ) | |
def generate_lists(self): | |
return self.__generate( self.list_of_strings ) | |
def generate_hashes(self): | |
return self.__generate( self.hash_of_strings ) | |
def generate_booleans(self): | |
return self.__generate( self.boolean ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment