Skip to content

Instantly share code, notes, and snippets.

@bryanhelmig
Created August 9, 2012 03:45
Show Gist options
  • Save bryanhelmig/3300760 to your computer and use it in GitHub Desktop.
Save bryanhelmig/3300760 to your computer and use it in GitHub Desktop.
import random
start = 0.05
end = 0.2
interval = 11
intervals = [0.0] * interval
step = (end - start) / (interval * 2) # adjust to taste, coarser might feel more "random"
# only continue while the gap between start and end isn't closed
while sum(intervals) < end - start:
# choose any of the intervals at random
selected_interval = random.choice(range(len(intervals)))
# and add a max of step to it, but let it wander
intervals[selected_interval] += random.random() * step # 0.0<->1.0 * step
# print each interval one at a time, creeping towards == end
current = start
for index, jump in enumerate(intervals):
print index + 1, current
current += jump
# now current > end, so print end
print interval + 1, end
"""
Sample output:
1 0.05
2 0.0670812001431
3 0.0731603308333
4 0.0938695948509
5 0.110838291447
6 0.12349751625
7 0.128899087855
8 0.132899586324
9 0.152122445973
10 0.158451754709
11 0.176311142846
12 0.2
1 0.05
2 0.0631051196776
3 0.0828884350645
4 0.106138502255
5 0.122898026945
6 0.125953330895
7 0.13924073949
8 0.149543128703
9 0.15977812608
10 0.169971766419
11 0.184387217361
12 0.2
1 0.05
2 0.0530942944775
3 0.0812515843015
4 0.103182306271
5 0.121195661082
6 0.139281124719
7 0.150184694858
8 0.164004538703
9 0.177599791515
10 0.190813105681
11 0.196775949207
12 0.2
1 0.05
2 0.0600850048193
3 0.0765072806909
4 0.0873747888335
5 0.106381751078
6 0.116279048657
7 0.13317365851
8 0.140663928472
9 0.157882222769
10 0.165471433813
11 0.189703927512
12 0.2
1 0.05
2 0.071477823268
3 0.0821715291754
4 0.0961085148012
5 0.100607659805
6 0.112511003635
7 0.120049587699
8 0.135752197501
9 0.144922691211
10 0.165078272469
11 0.190471216425
12 0.2
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment