After reviewing the random number test code I thought some extra functions might be useful, attached is said code<br><br><br clear="all"># -*- coding: utf-8 -*-<br>#<br># SelfTest/Util/test_generic.py: Self-test for the Crypto.Random.new() function<br>
#<br># =======================================================================<br># Copyright (C) 2008 Dwayne C. Litzenberger <<a href="mailto:dlitz@dlitz.net">dlitz@dlitz.net</a>><br>#<br># Permission is hereby granted, free of charge, to any person obtaining<br>
# a copy of this software and associated documentation files (the<br># "Software"), to deal in the Software without restriction, including<br># without limitation the rights to use, copy, modify, merge, publish,<br>
# distribute, sublicense, and/or sell copies of the Software, and to<br># permit persons to whom the Software is furnished to do so.<br>#<br># THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS<br># "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT<br>
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR<br># A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT<br># OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,<br>
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT<br># LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,<br># DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY<br># THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT<br>
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE<br># OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<br># =======================================================================<br>
#<br><br>"""Self-test suite for Crypto.Random.new()"""<br><br>__revision__ = "$Id$"<br><br>import unittest<br><br>class SimpleTest(unittest.TestCase):<br> def runTest(self):<br> """Crypto.Random.new()"""<br>
# Import the OSRNG module and try to use it<br> from Crypto import Random<br> randobj = Random.new()<br> x = randobj.read(16)<br> y = randobj.read(16)<br> self.assertNotEqual(x, y)<br>
class TestNotAlwaysEqual(unittest.TestCase):<br> def runTest(self):<br> from Crypto import Random<br> randobj = Random.new()<br> k = 10<br> DataArray = []<br> x = randobj.read(16)<br>
count = 0<br> for i in range(0,k):<br> y = randobj.read(16)<br> if x == y:<br> count += 1<br> self.assertNotEqual(count,k)<br>class TestAverage(unittest.TestCase):<br>
def runTest(self):<br> from Crypto import Random<br> randobj = Random.new()<br> x = randobj.read(2**15)<br> values = []<br> for i in x:<br> values.append(ord(i))<br> total = 0<br>
for i in values:<br> total += i<br> average = total/len(values)<br> print average<br> self.assertEqual(average in range((256/2)-28,(256/2)+28),True) <br>
<br>def get_tests():<br> return [SimpleTest(),TestNotAlwaysEqual(),TestAverage()]<br><br>if __name__ == '__main__':<br> suite = lambda: unittest.TestSuite(get_tests())<br> unittest.main(defaultTest='suite')<br>
<br># vim:set ts=4 sw=4 sts=4 expandtab:<br><br>-- <br>Sam Phippen<br><br>Please avoid sending me Word or PowerPoint attachments.<br>See <a href="http://www.gnu.org/philosophy/no-word-attachments.html">http://www.gnu.org/philosophy/no-word-attachments.html</a><br>