Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

prog challenge

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 ].

Name: Anonymous 2010-09-13 13:17

from random import randrange as rand
m = int(raw_input("max: "))
a = int(raw_input("average: "))
l = int(raw_input("length: "))

seq = [a] * l
while max(seq) < m:
    seq[rand(l)] -= 1
    seq[rand(l)] += 1
print seq

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List