Skip to content

Commit b55945f

Browse files
Smart Random v0.0.1
1 parent dbc70cd commit b55945f

File tree

5 files changed

+124
-3
lines changed

5 files changed

+124
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,4 @@ cython_debug/
157157
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160-
#.idea/
160+
.idea/

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2023, Smart Bear
3+
Copyright (c) 2023, A.A Suvorov
44

55
Redistribution and use in source and binary forms, with or without
66
modification, are permitted provided that the following conditions are met:

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,49 @@
1-
# smartrandom
1+
# smartrandom
2+
3+
---
4+
5+
## Random Data Generators:
6+
7+
Allows you to generate random strings of a given length from letters, numbers, symbols.
8+
Helps to generate passwords, service codes (for example, for sending via SMS), hashes and much more.
9+
---
10+
11+
## Help:
12+
13+
```python
14+
from smartrandom.random_master import RandomMaster
15+
16+
random_string = RandomMaster.string.get(length=10)
17+
random_number_string = RandomMaster.number.get(length=10)
18+
password = RandomMaster.password.get(length=10)
19+
random_hash = RandomMaster.hash.get(text='give me hash')
20+
random_number_code = RandomMaster.get_code(length=10, number_flag=True)
21+
random_string_code = RandomMaster.get_code(length=10, string_flag=True)
22+
random_symbol_code = RandomMaster.get_code(length=10, symbol_flag=True)
23+
24+
```
25+
26+
***
27+
28+
## Disclaimer of liability:
29+
30+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
33+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
34+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
38+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40+
41+
***
42+
43+
## Copyright:
44+
--------------------------------------------------------
45+
Licensed under the terms of the BSD 3-Clause License
46+
(see LICENSE for details).
47+
Copyright © 2018-2023, A.A Suvorov
48+
All rights reserved.
49+
--------------------------------------------------------

smartrandom/__init__.py

Whitespace-only changes.

smartrandom/random_master.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# -*- coding: utf-8 -*-
2+
# --------------------------------------------------------
3+
# Licensed under the terms of the BSD 3-Clause License
4+
# (see LICENSE for details).
5+
# Copyright © 2018-2023, A.A Suvorov
6+
# All rights reserved.
7+
# --------------------------------------------------------
8+
# https://github.com/smartlegionlab
9+
# --------------------------------------------------------
10+
import hashlib
11+
import random
12+
import string
13+
14+
15+
class RandomStringMaster:
16+
letters = string.ascii_letters
17+
18+
@classmethod
19+
def get(cls, length=10):
20+
return ''.join((random.choice(cls.letters) for _ in range(length)))
21+
22+
23+
class RandomNumberMaster:
24+
numbers = string.digits
25+
26+
@classmethod
27+
def get(cls, length=10):
28+
return ''.join((random.choice(cls.numbers) for _ in range(length)))
29+
30+
31+
class RandomSymbolMaster:
32+
symbols = '@$!%*#?&-'
33+
34+
@classmethod
35+
def get(cls, length=10):
36+
return ''.join((random.choice(cls.symbols) for _ in range(length)))
37+
38+
39+
class RandomPasswordMaster:
40+
letters = string.ascii_letters
41+
numbers = string.digits
42+
symbols = '@$!%*#?&-'
43+
44+
@classmethod
45+
def get(cls, length=10):
46+
return ''.join((random.choice(cls.letters + cls.numbers + cls.symbols) for _ in range(length)))
47+
48+
49+
class RandomHashMaster:
50+
@classmethod
51+
def get(cls, text):
52+
sha = hashlib.sha3_512(text.encode('utf-8'))
53+
new_hash = sha.hexdigest()
54+
return new_hash
55+
56+
57+
class RandomMaster:
58+
string = RandomStringMaster()
59+
number = RandomNumberMaster()
60+
symbol = RandomSymbolMaster()
61+
password = RandomPasswordMaster()
62+
hash = RandomHashMaster()
63+
64+
@classmethod
65+
def get_code(cls, length=10, number_flag=False, string_flag=False, symbol_flag=False):
66+
data = ''
67+
if string_flag:
68+
data += cls.string.letters
69+
if number_flag:
70+
data += cls.number.numbers
71+
if symbol_flag:
72+
data += cls.symbol.symbols
73+
return ''.join((random.choice(data) for _ in range(length)))

0 commit comments

Comments
 (0)