Lines Matching refs:random

3 import random
22 """Helper function to make a list of random numbers"""
23 return [self.gen.random() for i in range(n)]
64 @unittest.mock.patch('random._urandom') # os.urandom
94 # actually happen in a genuinely random shuffle, it is
305 # Test consistency with random.choice() for empty population
315 # in choices() when the value returned by random() was large
316 # enough to make `random() * total` round up to the total.
349 x1 = self.gen.random()
353 x2 = self.gen.random()
387 origseq = [self.gen.random() for i in range(10)]
389 restoredseq = [newgen.random() for i in range(10)]
402 self.assertEqual(int(r.random()*1000), value)
405 # Had problem with an uneven distribution in int(n*random())
433 random.SystemRandom().random()
439 @unittest.skipUnless(SystemRandom_available, "random.SystemRandom not available")
441 gen = random.SystemRandom()
469 cum |= int(self.gen.random() * span)
594 self.assertEqual(r1.random(), r2.random())
598 gen = random.Random()
603 self.assertEqual([self.gen.random().hex() for i in range(4)],
607 self.assertEqual([self.gen.random().hex() for i in range(4)],
615 self.assertEqual([self.gen.random().hex() for i in range(4)],
620 self.assertEqual([self.gen.random().hex() for i in range(4)],
625 self.assertEqual([self.gen.random().hex() for i in range(4)],
647 self.assertEqual([self.gen.random().hex() for i in range(4)],
652 self.assertEqual([self.gen.random().hex() for i in range(4)],
657 self.assertEqual([self.gen.random().hex() for i in range(4)],
663 self.assertEqual([self.gen.random().hex() for i in range(4)],
702 # code. Create 2000 53-bit precision random floats. Compare only
705 # list of expected random numbers:
767 cum |= int(self.gen.random() * span)
834 # Random._randbelow() can only use random() when the built-in one
836 maxsize = 1<<random.BPF
851 # r = random()
853 # r = random() # <== *This line* <==<
856 # once, we need to mock random() so that it returns a number greater
862 with unittest.mock.patch.object(random.Random, 'random') as random_mock:
951 gen2 = random.Random()
960 # We run this test on random.Random() which makes deterministic selections
1007 g = random.Random()
1008 x = [g.random() for i in range(50)] + [0.0]*5
1009 g.random = x[:].pop; g.uniform(1,10)
1010 g.random = x[:].pop; g.paretovariate(1.0)
1011 g.random = x[:].pop; g.expovariate(1.0)
1012 g.random = x[:].pop; g.weibullvariate(1.0, 1.0)
1013 g.random = x[:].pop; g.vonmisesvariate(1.0, 1.0)
1014 g.random = x[:].pop; g.normalvariate(0.0, 1.0)
1015 g.random = x[:].pop; g.gauss(0.0, 1.0)
1016 g.random = x[:].pop; g.lognormvariate(0.0, 1.0)
1017 g.random = x[:].pop; g.vonmisesvariate(0.0, 1.0)
1018 g.random = x[:].pop; g.gammavariate(0.01, 1.0)
1019 g.random = x[:].pop; g.gammavariate(1.0, 1.0)
1020 g.random = x[:].pop; g.gammavariate(200.0, 1.0)
1021 g.random = x[:].pop; g.betavariate(3.0, 3.0)
1022 g.random = x[:].pop; g.triangular(0.0, 1.0, 1.0/3.0)
1027 g = random.Random()
1039 g.random = x[:].pop
1057 g = random.Random()
1079 g = random.Random()
1086 0 <= sample <= random.TWOPI,
1092 random.vonmisesvariate(0, 1e15)
1093 random.vonmisesvariate(0, 1e100)
1097 self.assertRaises(ValueError, random.gammavariate, -1, 3)
1098 self.assertRaises(ValueError, random.gammavariate, 0, 2)
1099 self.assertRaises(ValueError, random.gammavariate, 2, 0)
1100 self.assertRaises(ValueError, random.gammavariate, 1, -3)
1103 # of random.gammavariate(), depending on the value of 'alpha'. What we
1104 # are going to do here is to fix the values returned by random() to
1106 @unittest.mock.patch('random.Random.random')
1110 # We want the first random number to be outside the
1114 returned_value = random.gammavariate(1.1, 2.3)
1117 @unittest.mock.patch('random.Random.random')
1122 # Then random.random() returns 0.45,
1125 returned_value = random.gammavariate(1.0, 3.14)
1128 @unittest.mock.patch('random.Random.random')
1135 gammavariate_returned_value = random.gammavariate(1.0, beta)
1136 expovariate_returned_value = random.expovariate(1.0 / beta)
1139 @unittest.mock.patch('random.Random.random')
1148 # u = random()
1155 # u1 = random()
1164 # b*random() <= 1.0
1165 # r1 = random() <= 1.0 / b
1170 # r2 = random() <= _exp(-x)
1174 _e = random._e
1175 _exp = random._exp
1176 _log = random._log
1185 # These four "random" values result in the following trace:
1189 returned_value = random.gammavariate(alpha, beta)
1206 returned_value = random.gammavariate(alpha, beta)
1209 @unittest.mock.patch('random.Random.gammavariate')
1214 self.assertEqual(0.0, random.betavariate(2.71828, 3.14159))
1220 class Subclass(random.Random):
1222 random.Random.__init__(self)
1226 # Subclasses with an overridden random, but only the original
1230 # subclass providing its own random **and** getrandbits methods
1231 # like random.SystemRandom does => keep relying on getrandbits for
1233 class SubClass1(random.Random):
1234 def random(self):
1235 called.add('SubClass1.random')
1236 return random.Random.random(self)
1240 return random.Random.getrandbits(self, n)
1245 # subclass providing only random => can only use random for randrange
1246 class SubClass2(random.Random):
1247 def random(self):
1248 called.add('SubClass2.random')
1249 return random.Random.random(self)
1252 self.assertEqual(called, {'SubClass2.random'})
1254 # subclass defining getrandbits to complement its inherited random
1259 return random.Random.getrandbits(self, n)
1264 # subclass providing only random and inherited getrandbits
1265 # => random takes precedence
1267 def random(self):
1268 called.add('SubClass4.random')
1269 return random.Random.random(self)
1272 self.assertEqual(called, {'SubClass4.random'})
1274 # Following subclasses don't define random or getrandbits directly,
1277 def random(self):
1278 called.add('Mixin1.random')
1279 return random.Random.random(self)
1283 return random.Random.getrandbits(self, n)
1285 class SubClass5(Mixin1, random.Random):
1289 self.assertEqual(called, {'Mixin1.random'})
1291 class SubClass6(Mixin2, random.Random):
1297 class SubClass7(Mixin1, Mixin2, random.Random):
1301 self.assertEqual(called, {'Mixin1.random'})
1303 class SubClass8(Mixin2, Mixin1, random.Random):
1312 self.assertAlmostEqual(random.NV_MAGICCONST, 1.71552776992141)
1313 self.assertAlmostEqual(random.TWOPI, 6.28318530718)
1314 self.assertAlmostEqual(random.LOG4, 1.38629436111989)
1315 self.assertAlmostEqual(random.SG_MAGICCONST, 2.50407739677627)
1319 self.assertTrue(set(random.__all__) <= set(dir(random)))
1329 val = random.getrandbits(128)
1337 val = random.getrandbits(128)