Ignore:
Timestamp:
1 Apr 2010, 10:35:49 (15 years ago)
Author:
uli
Message:
  • Log creation of AC batches and their CSV files.
  • Optimize computation of random numbers.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py

    r5110 r5112  
    6363        """Create the entries for this batch.
    6464        """
    65         self._used = []
     65        rands = self.getNewRandomNum(num=self.entry_num)
    6666        for num in range(self.entry_num):
    67             random_num = self.getNewRandomNum()
    68             ac = AccessCode(num, random_num, self.cost)
     67            ac = AccessCode(num, rands[num], self.cost)
    6968            self[str(num)] = ac
    70         del self._used
    71 
    72     def getNewRandomNum(self):
    73         """Create a random number of 10 digits.
     69        return
     70       
     71    def getNewRandomNum(self, num=1):
     72        """Create a set of ``num`` random numbers of 10 digits each.
    7473
    7574        The number is returned as string.
    7675        """
    77         result = ''
    78         while result == '' or result in self._used:
    79             result = ''
     76        results = {}
     77        while len(results) < num:
     78            pin = ''
    8079            for x in range(10):
    81                 result += str(random().randint(0, 9))
    82         self._used.append(result)
    83         return result
     80                pin += str(random().randint(0, 9))
     81            results[pin] = True
     82        return results.keys()
    8483
    8584    def createCSVLogFile(self):
     
    109108                [str(value.batch_serial), str(value.representation)]
    110109                )
     110        logger = site.logger
     111        logger.info(
     112            "Created batch %s-%s" % (self.prefix, self.num))
     113        logger.info(
     114            "Written batch CSV to %s" % csv_path)
    111115        return os.path.basename(csv_path)
    112116
Note: See TracChangeset for help on using the changeset viewer.