Minor clean-up of function parameters in random().
authorRaymond Hettinger <python@rcn.com>
Sun, 6 Oct 2013 04:52:06 +0000 (21:52 -0700)
committerRaymond Hettinger <python@rcn.com>
Sun, 6 Oct 2013 04:52:06 +0000 (21:52 -0700)
1  2 
Lib/random.py

diff --cc Lib/random.py
index 3fac699d937db39786b5d24dbbe63662665b0b2a,35e5b4a063262a8f024dbaa9b7a0709dbef3ecc1..4a9fbd10594f1bf08623e4a8644caaaae922dda5
@@@ -254,21 -250,27 +253,27 @@@ class Random(_random.Random)
              raise IndexError('Cannot choose from an empty sequence')
          return seq[i]
  
-     def shuffle(self, x, random=None, int=int):
+     def shuffle(self, x, random=None):
 -        """x, random=random.random -> shuffle list x in place; return None.
 +        """Shuffle list x in place, and return None.
  
 -        Optional arg random is a 0-argument function returning a random
 -        float in [0.0, 1.0); by default, the standard random.random.
 +        Optional argument random is a 0-argument function returning a
 +        random float in [0.0, 1.0); if it is the default None, the
 +        standard random.random will be used.
  
--        Do not supply the 'int' argument.
          """
  
-         randbelow = self._randbelow
-         for i in reversed(range(1, len(x))):
-             # pick an element in x[:i+1] with which to exchange x[i]
-             j = randbelow(i+1) if random is None else int(random() * (i+1))
-             x[i], x[j] = x[j], x[i]
+         if random is None:
+             randbelow = self._randbelow
+             for i in reversed(range(1, len(x))):
+                 # pick an element in x[:i+1] with which to exchange x[i]
+                 j = randbelow(i+1)
+                 x[i], x[j] = x[j], x[i]
+         else:
+             _int = int
+             for i in reversed(range(1, len(x))):
+                 # pick an element in x[:i+1] with which to exchange x[i]
+                 j = _int(random() * (i+1))
+                 x[i], x[j] = x[j], x[i]
  
      def sample(self, population, k):
          """Chooses k unique random elements from a population sequence or set.