seeded_random.py 766 B

123456789101112131415161718192021222324
  1. '''This file is part of AToMPM - A Tool for Multi-Paradigm Modelling
  2. Copyright 2011 by the AToMPM team and licensed under the LGPL
  3. See COPYING.lesser and README.md in the root of this project for full details'''
  4. import random
  5. class SeededRandom(random.Random):
  6. '''
  7. Random class wrapper, provided a seeded random number generator
  8. '''
  9. __instantiated = False
  10. def __init__(self, seed=0):
  11. '''
  12. Singleton class: the single instance "INFINITY" stands for infinity.
  13. '''
  14. if SeededRandom.__instantiated:
  15. raise NotImplementedError("singleton class already instantiated")
  16. SeededRandom.__instantiatiated = True
  17. random.Random.__init__(self)
  18. self.seed(seed)
  19. Random = SeededRandom()