-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelpers.py
53 lines (38 loc) · 912 Bytes
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""Various helpers."""
from __future__ import division
import random
import string
__author__ = "Kevin Borgolte <[email protected]>, Giovanni Vigna <[email protected]>"
# ======
# Strings
def random_string(length=4, alphabet=string.ascii_uppercase):
return "".join(random.choice(alphabet) for _ in range(length))
# ===================
# Probability Helpers
def perfect():
return 1
def very_good():
attempt = random.random()
if attempt > 0.2:
return 1
return 0
def good():
attempt = random.random()
if attempt > 0.5:
return 1
return 0
def bad():
attempt = random.random()
if attempt > 0.8:
return 1
return 0
def no_overhead():
return 0.0
# ===========
# PoV Helpers
def always_all(total):
return total
def atmost_80pct(total):
return random.randint(0, total * 8 // 10)