Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve randomness (#101) #103

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ arch:
- amd64
- ppc64le
python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Installation

To install `shortuuid` you need:

- Python 3.x.
- Python 3.6+

If you have the dependencies, you have multiple options of installation:

Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ license = "BSD-3-Clause"
classifiers = [
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
Expand All @@ -23,7 +22,7 @@ include = ["COPYING"]
shortuuid = "shortuuid.cli:cli"

[tool.poetry.dependencies]
python = ">=3.5"
python = ">=3.6"

[build-system]
requires = ["poetry-core"]
Expand Down
4 changes: 2 additions & 2 deletions shortuuid/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import math
import os
import uuid as _uu
import secrets
from typing import List
from typing import Optional

Expand Down Expand Up @@ -104,8 +105,7 @@ def random(self, length: Optional[int] = None) -> str:
if length is None:
length = self._length

random_num = int(binascii.b2a_hex(os.urandom(length)), 16)
return int_to_string(random_num, self._alphabet, padding=length)[:length]
return "".join(secrets.choice(self._alphabet) for _ in range(length))

def get_alphabet(self) -> str:
"""Return the current alphabet used for new UUIDs."""
Expand Down
Loading