Commit f015b3f5 authored by Raymond Hettinger's avatar Raymond Hettinger

Neaten-up comments and warning message.

parent 05a505f1
...@@ -221,9 +221,8 @@ class Random(_random.Random): ...@@ -221,9 +221,8 @@ class Random(_random.Random):
getrandbits = self.getrandbits getrandbits = self.getrandbits
# Only call self.getrandbits if the original random() builtin method # Only call self.getrandbits if the original random() builtin method
# has not been overridden or if a new getrandbits() was supplied. # 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: 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: while r >= n:
r = getrandbits(k) r = getrandbits(k)
return r return r
...@@ -231,11 +230,12 @@ class Random(_random.Random): ...@@ -231,11 +230,12 @@ class Random(_random.Random):
# so we can only use random() from here. # so we can only use random() from here.
if k > bpf: if k > bpf:
_warn("Underlying random() generator does not supply \n" _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) return int(self.random() * n)
random = self.random random = self.random
N = 1 << k N = 1 << k
r = int(N * random()) r = int(N * random()) # 0 <= r < 2**k
while r >= n: while r >= n:
r = int(N * random()) r = int(N * random())
return r return r
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment