choosing random numbers with weights/probability?

Darrell news at dorb.com
Mon Jun 21 20:49:21 CEST 1999


I'm no expert but....

import whrandom

def popList(l):
 selList=[]
 for i in l:
  for v in range(i[1]):
   selList.append(i[0])
 return selList

list=popList([('one',25),('two',50),('three',25)])
item=whrandom.choice(list)


--
--Darrell






More information about the Python-list mailing list