TickBasedRandom.py 533 B

12345678910111213141516171819202122
  1. #!/usr/bin/env python2
  2. import time, random, decimal, sys
  3. ticks = 0.0
  4. random.seed(0.0)
  5. def GetInteger(min, max):
  6. global ticks
  7. currentTicks = time.time()
  8. if currentTicks != ticks:
  9. ticks = currentTicks
  10. random.seed(ticks)
  11. return int(round(min + decimal.Decimal(random.random()) * (max-min)))
  12. def SortRandom(inputList):
  13. output = []
  14. while len(inputList) > 0:
  15. index = GetInteger(0, len(inputList) - 1)
  16. output.append(inputList[index])
  17. del inputList[index]
  18. return output