Created
April 11, 2019 13:51
-
-
Save Tattoo/31ba06cdd374c5d09165c2817bc13d7f to your computer and use it in GitHub Desktop.
Some fake data generation in Python 3
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
from decimal import Decimal | |
from pprint import pprint | |
from random import choice, choices, randint | |
def random_digits(n): | |
"""Returns int with length `n`""" | |
start = 10**(n-1) | |
end = (10**n)-1 | |
return randint(start, end) | |
def random_precision(x, y): | |
"""return string of a decimal which in total is of length `x` with `y` places after radix point""" | |
return str(Decimal(random_digits(x))/(10**y)) # very big `x` must be Decimals instead of normal floats! | |
# characters Harrison-Stetson'ed from: http://www.columbia.edu/~fdc/utf8/index.html#notes | |
# selection around the world | |
CHARS='abcdefghijklmnopqrstuvwxyzχçéñônàășíåðæøäöëüзыянõēęžłıħġ我べ않아요'.upper() | |
pprint([ | |
random_digits(7), | |
random_precision(23, 2), | |
(lambda n: ''.join(choices(CHARS, k=n)))(255), | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment