From 1184ae38fb7cd07de5bb82c76cc3c4365cf44565 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Tue, 4 Jun 2019 21:25:50 +0300 Subject: [PATCH] Revert "Convert functionality to pysol-cards mod." This reverts commit 74441a1746dc81bd7f0b8eaab698a48c66605886 which appears to have caused a tests slowdown: https://github.com/shlomif/PySolFC/issues/119 . --- .appveyor.yml | 1 - .travis.yml | 2 +- pysollib/pysolrandom.py | 22 +++++++++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index c7824d8b..6ceeb22e 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,7 +14,6 @@ install: - python3 -mpip install py2exe - python3 -mpip install pycotap - python3 -mpip install pygame - - python3 -mpip install pysol-cards - python3 -mpip install random2 - python3 -mpip install six - perl -v diff --git a/.travis.yml b/.travis.yml index acfb94a6..b46e5b56 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ before_install: install: - sudo cpanm --notest Capture::Tiny - sudo cpanm Code::TidyAll::Plugin::Flake8 Perl::Tidy Test::Code::TidyAll Test::Differences Test::TrailingSpace - - export PY_MODS='pycotap pysol-cards random2 six' + - export PY_MODS='pycotap random2 six' - "`which python3` -m pip install --upgrade flake8 flake8-import-order $PY_MODS" - "sudo /usr/bin/python3 -m pip install --upgrade $PY_MODS || true" - "sudo `which python2` -m pip install --upgrade $PY_MODS" diff --git a/pysollib/pysolrandom.py b/pysollib/pysolrandom.py index a7b186cd..4c733394 100644 --- a/pysollib/pysolrandom.py +++ b/pysollib/pysolrandom.py @@ -34,8 +34,6 @@ except ImportError: "You need to install " + "https://pypi.python.org/pypi/random2 using pip or similar.") -from pysol_cards.random import RandomBase # noqa: I100 - # ************************************************************************ # * Abstract class for PySol Random number generator. @@ -44,7 +42,7 @@ from pysol_cards.random import RandomBase # noqa: I100 # ************************************************************************ -class BasicRandom(RandomBase): +class BasicRandom: # MAX_SEED = 0L # MAX_SEED = 0xffffffffffffffffL # 64 bits MAX_SEED = int('100000000000000000000') # 20 digits @@ -174,9 +172,20 @@ class MFXRandom(BasicRandom): def choice(self, seq): return seq[int(self.random() * len(seq))] + # Get a random integer in the range [a, b] including both end points. + def randint(self, a, b): + return a + int(self.random() * (b+1-a)) + def randrange(self, a, b): return self.randint(a, b-1) + def shuffle(self, seq): + n = len(seq) - 1 + while n > 0: + j = self.randint(0, n) + seq[n], seq[j] = seq[j], seq[n] + n -= 1 + # ************************************************************************ # * Linear Congruential random generator @@ -261,6 +270,13 @@ class LCRandom31(MFXRandom): return a + (ret % (b+1-a)) + def shuffle(self, seq): + n = len(seq) - 1 + while n > 0: + j = self.randint(0, n) + seq[n], seq[j] = seq[j], seq[n] + n -= 1 + def reset(self): self.setSeed(self.seed)