Created
May 5, 2015 14:58
-
-
Save PirosB3/4638dcb8b1b387c132c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
import math | |
def random_number_generator(base, power, base_num): | |
if power == 1: | |
return base() | |
return int((base_num ** (power-1)) * base() + random_number_generator(base, power-1, base_num)) | |
def generate_given(rand_num, target_rand_range): | |
if target_rand_range < rand_num: | |
while True: | |
n = random_number_generator(lambda: random.randint(0, rand_num-1), 1, rand_num) | |
if target_rand_range < n: | |
return target_rand_range % n | |
power = math.ceil(math.log(target_rand_range, rand_num)) | |
while True: | |
n = random_number_generator(lambda: random.randint(0, rand_num-1), power, rand_num) | |
if n < target_rand_range: | |
return n % target_rand_range | |
from collections import Counter | |
c = Counter((generate_given(12, 200) for _ in xrange(20000))) | |
import ipdb; ipdb.set_trace() | |
#print Counter((random_number_generator(lambda: random.randint(0, 3), 3, 4) for _ in xrange(200000))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment