]> granicus.if.org Git - python/commitdiff
Neaten-up comments and warning message.
authorRaymond Hettinger <python@rcn.com>
Tue, 7 Sep 2010 20:04:42 +0000 (20:04 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 7 Sep 2010 20:04:42 +0000 (20:04 +0000)
Lib/random.py

index b2a3d51452c912b6cad2feb6cd5a0b3d4239a26f..0aee06eb29d45c022371d41ff1c493b75e6cdb85 100644 (file)
@@ -221,9 +221,8 @@ class Random(_random.Random):
         getrandbits = self.getrandbits
         # Only call self.getrandbits if the original random() builtin method
         # has not been overridden or if a new getrandbits() was supplied.
-        # This assures that the two methods correspond.
         if type(self.random) is BuiltinMethod or type(getrandbits) is Method:
-            r = getrandbits(k)  # 0 <= r < 2**k
+            r = getrandbits(k)          # 0 <= r < 2**k
             while r >= n:
                 r = getrandbits(k)
             return r
@@ -231,11 +230,12 @@ class Random(_random.Random):
         # so we can only use random() from here.
         if k > bpf:
             _warn("Underlying random() generator does not supply \n"
-                "enough bits to choose from a population range this large")
+                "enough bits to choose from a population range this large.\n"
+                "To remove the range limitation, add a getrandbits() method.")
             return int(self.random() * n)
         random = self.random
         N = 1 << k
-        r = int(N * random())
+        r = int(N * random())           # 0 <= r < 2**k
         while r >= n:
             r = int(N * random())
         return r