1
Name:
Anonymous
2010-09-13 8:38
Create a sequence of random integers with the following given: max, average, length
Example, with m = 7, a = 4, l = 5, you get [ 5, 2, 2, 4, 7 ].
41
Name:
Anonymous
2010-09-16 12:33
>>37
Even if they are nonnegative (sic) integers, the randomly chosen upper bound will almost surely require more than any finite amount of space to represent.
42
Name:
Anonymous
2010-09-16 12:37
randomly chosen upper bound
( ≖‿≖)
46
Name:
Anonymous
2010-09-20 7:20
Just a reminder: a solution has already been presented
[1] yet none of you fucktards are intelligent enough to understand it.
[1]:
http://pastebin.com/UQgGuJpm
49
Name:
Anonymous
2010-09-20 14:18
>>46
Entries posted to 3rd party sites are not accepted or even reviewed. Entries exceeding the post limit are disqualified.
51
Name:
Anonymous
2010-09-21 4:55
import random
def memoized(f):
d = {}
def wrapper(*args):
if args not in d:
d[args] = f(*args)
return d[args]
return wrapper
@memoized
def cnt(ncnt, nsum, nmax):
if ncnt == 1:
return 1 if nsum <= nmax else 0
if nsum == 0:
return 1
return sum(cnt(ncnt - 1, nsum - cur, nmax)
for cur in range(min(nsum, nmax) + 1))
def select(ncnt, nsum, nmax, n):
if ncnt == 1:
assert n == 0
assert nsum <= nmax
return [nsum]
for cur in range(nmax + 1):
c = cnt(ncnt - 1, nsum - cur, nmax)
if n < c:
return [cur] + select(ncnt - 1, nsum - cur, nmax, n)
n -= c
assert False, 'overflow, %d remaining' % n
def select_random(ncnt, nsum, nmax):
total = cnt(ncnt, nsum, nmax)
n = random.randrange(0, total)
r = select(ncnt, nsum, nmax, n)
# print '%d of %d' % (n, total)
return r
if __name__ == '__main__':
try:
for i in range(28):
print '%3d' % i, select(3, 7, 5, i)
except AssertionError as err:
print err
for i in range(10):
print select_random(20, 200, 20)
print select_random(1, 15, 20)
for i in range(20):
print select_random(2, 1, 1)
52
Name:
Anonymous
2010-09-21 11:15
>>50
I can't help it if it's true.
57
Name:
Anonymous
2010-12-06 9:40
B a c k t o / b / , ` ` G N A A F a g g o t ' '
63
Name:
Anonymous
2010-12-13 14:50
>>58
>>59
>>60
>>61
>>62
You are severely diminishing the quality of this thread, consider leaving
/prog/ or consider stop posting, thank you.
65
Name:
Anonymous
2010-12-13 16:26
>>63
l2quote faggot || gb2/b/ xD
lmao enjoy ban
66
Name:
Anonymous
2010-12-13 16:30
>>-,,,,,,-,--,,,-,,-
Go back to /b/, ``please''.
68
Name:
Anonymous
2010-12-13 21:19
>>40,44-48,50-67
I don't really get it... what's the point of this?
This really could be a good board... Maybe if we just modded this shit away...
69
Name:
Anonymous
2010-12-13 21:35
>>68
Sometimes we get modded. Sometimes.
70
Name:
Anonymous
2010-12-13 22:00
don't mind me, just keeping a shit thread bumped