Skip to content

Commit 7601e00

Browse files
authored
Merge pull request #20 from cisagov/bugfix/issue-19
Add support for Python 3.11
2 parents 3f2fd33 + 1e8ae02 commit 7601e00

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ jobs:
112112
fail-fast: false
113113
matrix:
114114
python-version:
115-
- "3.6"
116115
- "3.7"
117116
- "3.8"
118117
- "3.9"
119118
- "3.10"
119+
- "3.11"
120120
steps:
121121
- uses: actions/checkout@v3
122122
- id: setup-python
@@ -199,11 +199,11 @@ jobs:
199199
fail-fast: false
200200
matrix:
201201
python-version:
202-
- "3.6"
203202
- "3.7"
204203
- "3.8"
205204
- "3.9"
206205
- "3.10"
206+
- "3.11"
207207
steps:
208208
- uses: actions/checkout@v3
209209
- id: setup-python

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ repos:
101101
rev: 22.3.0
102102
hooks:
103103
- id: black
104-
- repo: https://gitlab.com/pycqa/flake8
105-
rev: 3.9.2
104+
- repo: https://github.com/PyCQA/flake8
105+
rev: 5.0.4
106106
hooks:
107107
- id: flake8
108108
additional_dependencies:

src/lcgit/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""This file defines the version of this module."""
2-
__version__ = "0.1.0"
2+
__version__ = "0.1.1"

src/lcgit/lcgit.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from collections.abc import Sequence
1414
from ipaddress import _BaseNetwork
1515
from math import sin
16-
from random import randint, shuffle
16+
from random import Random, randint
1717

1818

1919
def _lcg_params(u, v):
@@ -102,8 +102,11 @@ def __iter__(self):
102102
"""
103103
seed = self.seed
104104
index = self.index
105+
106+
# The LCG algorithm requires a sequence of more than 4 elements to operate.
107+
# If the sequence is not sufficiently large, we will fall back to the shuffle method.
105108
if self.seqlength > 4:
106-
# use LCG
109+
# Sequence is large enough to use LCG algorithm
107110
while index < self.seqlength:
108111
while True:
109112
seed = (seed * self.multiplier + self.increment) % self.modulus
@@ -115,12 +118,13 @@ def __iter__(self):
115118
else:
116119
yield self.seq[seed]
117120
else:
118-
# use shuffle
121+
# Sequence is too small to use LCG algorithm, use shuffle instead
119122
shuffled_seq = list(self.seq)
120-
shuffle(
121-
shuffled_seq,
122-
random=lambda: abs(sin(self.multiplier + self.increment + seed)),
123+
seeded_random = Random()
124+
seeded_random.seed(
125+
abs(sin(self.multiplier + self.increment + seed)), version=1
123126
)
127+
seeded_random.shuffle(shuffled_seq)
124128
for i in shuffled_seq[index:]:
125129
index += 1
126130
if self.emit:

0 commit comments

Comments
 (0)