我对使用以下代码的输出感到困惑,我想用随机数初始化10个范围的簇。但是,结果都是一样的。
import random
class range_cluster:
def __init__(self,ranges=[]):
self.ranges = ranges
def generate_range_cluster(nclusters):
range_clusters = [range_cluster() for _ in xrange(nclusters)]
for rc in range_clusters:
rc.ranges.append([random.random(),random.random()])
return range_clusters
def main():
nclusters = 10
range_clusters = generate_range_cluster(nclusters)
for rc in range_clusters:
print rc.ranges[0][0],rc.ranges[0][1]
main()
结果:
0.60436009302 0.361964915468
0.60436009302 0.361964915468
0.60436009302 0.361964915468
0.60436009302 0.361964915468
0.60436009302 0.361964915468
0.60436009302 0.361964915468
0.60436009302 0.361964915468
0.60436009302 0.361964915468
0.60436009302 0.361964915468
0.60436009302 0.361964915468