Skip to content

Commit be6ab2d

Browse files
Smart Random v0.1.0 Corrected errors. Code refactoring. Stable version.
1 parent a929f5f commit be6ab2d

File tree

5 files changed

+80
-43
lines changed

5 files changed

+80
-43
lines changed

README.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# smartrandom <sup>v0.0.3</sup>
1+
# smartrandom <sup>v0.1.0</sup>
22
---
33

44
## Random Data Generators:
55

6-
Allows you to generate random strings of a given length from letters, numbers, symbols.
7-
Helps to generate passwords, service codes (for example, for sending via SMS), hashes and much more.
6+
Allows you to generate random strings of a given length from letters, numbers, and symbols.
7+
Helps to generate passwords, service codes (for example, for sending via SMS), hashes, and much more.
8+
89
---
910

1011
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/smartlegionlab/smartrandom)](https://github.com/smartlegionlab/smartrandom/)
@@ -14,19 +15,25 @@ Helps to generate passwords, service codes (for example, for sending via SMS), h
1415
[![GitHub](https://img.shields.io/github/license/smartlegionlab/smartrandom)](https://github.com/smartlegionlab/smartrandom/blob/master/LICENSE)
1516
[![PyPI - Format](https://img.shields.io/pypi/format/smartrandom)](https://pypi.org/project/smartrandom)
1617

18+
***
19+
20+
Author and developer: ___A.A Suvorov.___
21+
22+
***
1723

1824
## Help:
1925

26+
`pip install smartrandom`
27+
2028
```python
21-
from smartrandom.random_master import RandomMaster
22-
23-
random_string = RandomMaster.string.create(length=10)
24-
random_number_string = RandomMaster.number.create(length=10)
25-
password = RandomMaster.password.create(length=10)
26-
random_hash = RandomMaster.hash.create(text='give me hash')
27-
random_number_code = RandomMaster.create_code(length=10, number_flag=True)
28-
random_string_code = RandomMaster.create_code(length=10, string_flag=True)
29-
random_symbol_code = RandomMaster.create_code(length=10, symbol_flag=True)
29+
from smartrandom.random_master import RandomStringMaster
30+
31+
random_string = RandomStringMaster.create_string(length=10)
32+
string_hash = RandomStringMaster.create_hash('text')
33+
number_code = RandomStringMaster.create_numeric_code(length=6)
34+
letter_code = RandomStringMaster.create_letters_code(length=6)
35+
symbol_code = RandomStringMaster.create_letters_code(length=6)
36+
code = RandomStringMaster.create_code(length=10, numeric_flag=True, letters_flag=True, symbols_flag=True)
3037

3138
```
3239

setup.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = smartrandom
33
version = attr: smartrandom.__version__
44
author = A.A Suvorov
55
author_email = [email protected]
6-
description = Random Data Generators
6+
description = Random Data Generators.
77
long_description = file: README.md
88
long_description_content_type = text/markdown
99
url = https://github.com/smartlegionlab/smartrandom/
@@ -22,6 +22,10 @@ classifiers =
2222

2323
keywords =
2424
password generator
25+
code generator
26+
random generator
27+
random code generator
28+
random string generator
2529
smartrandom
2630
smartlegionlab
2731

setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# --------------------------------------------------------
2+
# Licensed under the terms of the BSD 3-Clause License
3+
# (see LICENSE for details).
4+
# Copyright © 2018-2024, A.A Suvorov
5+
# All rights reserved.
6+
# --------------------------------------------------------
7+
# https://github.com/smartlegionlab
8+
# --------------------------------------------------------
19
from setuptools import setup, find_packages
210

311
setup(

smartrandom/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66
# --------------------------------------------------------
77
# https://github.com/smartlegionlab
88
# --------------------------------------------------------
9-
"""Smart Random"""
10-
__version__ = '0.0.3'
9+
"""Smart Random - Random Data Generators.
10+
11+
Allows you to generate random strings of a given length from letters, numbers, and symbols.
12+
Helps to generate passwords, service codes (for example, for sending via SMS), hashes, and much more.
13+
"""
14+
__version__ = '0.1.0'

smartrandom/random_master.py

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,81 @@
66
# --------------------------------------------------------
77
# https://github.com/smartlegionlab
88
# --------------------------------------------------------
9+
"""Random Data Generators."""
910
import hashlib
1011
import random
1112
import string
1213

1314

14-
class RandomStringMaster:
15+
class RandomLettersMaster:
1516
letters = string.ascii_letters
1617

1718
@classmethod
1819
def create(cls, length=10):
1920
return ''.join((random.choice(cls.letters) for _ in range(length)))
2021

2122

22-
class RandomNumberMaster:
23+
class RandomNumericMaster:
2324
numbers = string.digits
2425

2526
@classmethod
2627
def create(cls, length=10):
2728
return ''.join((random.choice(cls.numbers) for _ in range(length)))
2829

2930

30-
class RandomSymbolMaster:
31+
class RandomSymbolsMaster:
3132
symbols = '@$!%*#?&-'
3233

3334
@classmethod
3435
def create(cls, length=10):
3536
return ''.join((random.choice(cls.symbols) for _ in range(length)))
3637

3738

38-
class RandomPasswordMaster:
39-
letters = string.ascii_letters
40-
numbers = string.digits
41-
symbols = '@$!%*#?&-'
39+
class HashMaster:
40+
@classmethod
41+
def create(cls, text: str):
42+
text = str(text)
43+
sha = hashlib.sha3_512(text.encode('utf-8'))
44+
new_hash = sha.hexdigest()
45+
return new_hash
46+
47+
48+
class RandomStringMaster:
49+
letters_master = RandomLettersMaster()
50+
numeric_master = RandomNumericMaster()
51+
symbols_master = RandomSymbolsMaster()
52+
hash_master = HashMaster()
4253

4354
@classmethod
44-
def create(cls, length=10):
45-
return ''.join((random.choice(cls.letters + cls.numbers + cls.symbols) for _ in range(length)))
55+
def create_string(cls, length=10):
56+
random_string = cls.letters_master.letters + cls.numeric_master.numbers + cls.symbols_master.symbols
57+
return ''.join((random.choice(random_string) for _ in range(length)))
4658

59+
@classmethod
60+
def create_hash(cls, text):
61+
return cls.hash_master.create(text)
4762

48-
class RandomHashMaster:
4963
@classmethod
50-
def create(cls, text):
51-
sha = hashlib.sha3_512(text.encode('utf-8'))
52-
new_hash = sha.hexdigest()
53-
return new_hash
64+
def create_numeric_code(cls, length):
65+
return cls.numeric_master.create(length)
5466

67+
@classmethod
68+
def create_letters_code(cls, length):
69+
return cls.letters_master.create(length)
5570

56-
class RandomMaster:
57-
string = RandomStringMaster()
58-
number = RandomNumberMaster()
59-
symbol = RandomSymbolMaster()
60-
password = RandomPasswordMaster()
61-
hash = RandomHashMaster()
71+
@classmethod
72+
def create_symbols_code(cls, length):
73+
return cls.symbols_master.create(length)
6274

6375
@classmethod
64-
def create_code(cls, length=10, number_flag=False, string_flag=False, symbol_flag=False):
76+
def create_code(cls, length=10, numeric_flag=False, letters_flag=False, symbols_flag=False):
6577
data = ''
66-
if string_flag:
67-
data += cls.string.letters
68-
if number_flag:
69-
data += cls.number.numbers
70-
if symbol_flag:
71-
data += cls.symbol.symbols
72-
return ''.join((random.choice(data) for _ in range(length)))
78+
if letters_flag:
79+
data += cls.letters_master.letters
80+
if numeric_flag:
81+
data += cls.numeric_master.numbers
82+
if symbols_flag:
83+
data += cls.symbols_master.symbols
84+
if data:
85+
return ''.join((random.choice(data) for _ in range(length)))
86+
return None

0 commit comments

Comments
 (0)