[Python-checkins] python/nondist/sandbox/statistics statistics.py, 1.6, 1.7

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Tue Feb 17 12:39:29 EST 2004


Update of /cvsroot/python/python/nondist/sandbox/statistics
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7892

Modified Files:
	statistics.py 
Log Message:
Limit randomization to just the selection of the pivot rather than
shuffling the whole dataset.



Index: statistics.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/statistics/statistics.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** statistics.py	17 Feb 2004 13:00:16 -0000	1.6
--- statistics.py	17 Feb 2004 17:39:26 -0000	1.7
***************
*** 91,95 ****
      """
      try:
-         shuffled = False
          while True:
              it = iter(data)
--- 91,94 ----
***************
*** 109,115 ****
                  data = notunder
                  n -= len(under) + 1
!             if not shuffled and len(data)>8 and min(len(under), len(notunder)) == 0:
!                 random.shuffle(data)
!                 shuffled = True
      except StopIteration:
          raise ValueError('not enough elements for the given rank')
--- 108,114 ----
                  data = notunder
                  n -= len(under) + 1
!             if len(data) > 3:
!                 swap = random.randrange(len(data))
!                 data[0], data[swap] = data[swap], data[0]
      except StopIteration:
          raise ValueError('not enough elements for the given rank')




More information about the Python-checkins mailing list