From 565cce77e554b847d2dccd6cb0f98e127d6a16a4 Mon Sep 17 00:00:00 2001 From: Zachary Pavlov Date: Fri, 15 Jul 2005 21:28:54 +0000 Subject: [PATCH] Added a function for creating a non repeating random list of number. --- direct/src/showbase/PythonUtil.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index 6e555aa22c..ed459ed0dd 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -50,7 +50,19 @@ def indent(stream, numIndents, str): stream.write(' ' * numIndents + str) - +def nonRepeatingRandomList(vals,max): + random.seed(time.time()) + #first generate a set of random values + valueList=range(max) + finalVals=[] + for i in range(vals): + index=int(random.random()*len(valueList)) + finalVals.append(valueList[index]) + valueList.remove(valueList[index]) + return finalVals + + + def writeFsmTree(instance, indent = 0): if hasattr(instance, 'parentFSM'): writeFsmTree(instance.parentFSM, indent-2) @@ -62,7 +74,7 @@ def writeFsmTree(instance, indent = 0): - + if __debug__: class StackTrace: def __init__(self, label="", start=0, limit=None):