mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
*** empty log message ***
This commit is contained in:
parent
0c2a4f1550
commit
71839729a8
19
direct/src/directutil/WeightedChoice.py
Executable file
19
direct/src/directutil/WeightedChoice.py
Executable file
@ -0,0 +1,19 @@
|
||||
|
||||
import random
|
||||
|
||||
class WeightedChoice:
|
||||
def __init__(self, listOfLists, weightIndex=0):
|
||||
t=0
|
||||
for i in listOfLists:
|
||||
t+=i[weightIndex]
|
||||
self.total = t
|
||||
self.listOfLists = listOfLists
|
||||
self.weightIndex = weightIndex
|
||||
|
||||
def choose(self):
|
||||
roll = random.randrange(self.total)
|
||||
weight = self.weightIndex
|
||||
for i in self.listOfLists:
|
||||
roll -= i[weight]
|
||||
if roll <= 0:
|
||||
return i
|
Loading…
x
Reference in New Issue
Block a user