simple-rands 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GGN_2015
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.4
2
+ Name: simple-rands
3
+ Version: 0.0.1
4
+ Summary: a very simple tool to generate random string with digits and numbers.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: GGN_2015
8
+ Author-email: neko@jlulug.org
9
+ Requires-Python: >=3.10
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Description-Content-Type: text/markdown
18
+
19
+ # simple-rands
20
+ a very simple tool to generate random string with digits and numbers.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ pip install simple-rands
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```python
31
+ import simple_rands
32
+
33
+ # optional: set seed for generator
34
+ simple_rands.seed(12345)
35
+
36
+ length = 10
37
+ print(simple_rands.gen(length))
38
+ ```
39
+
@@ -0,0 +1,20 @@
1
+ # simple-rands
2
+ a very simple tool to generate random string with digits and numbers.
3
+
4
+ ## Install
5
+
6
+ ```bash
7
+ pip install simple-rands
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```python
13
+ import simple_rands
14
+
15
+ # optional: set seed for generator
16
+ simple_rands.seed(12345)
17
+
18
+ length = 10
19
+ print(simple_rands.gen(length))
20
+ ```
@@ -0,0 +1,17 @@
1
+ [project]
2
+ name = "simple-rands"
3
+ version = "0.0.1"
4
+ description = "a very simple tool to generate random string with digits and numbers."
5
+ authors = [
6
+ {name = "GGN_2015",email = "neko@jlulug.org"}
7
+ ]
8
+ license = {text = "MIT"}
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ dependencies = [
12
+ ]
13
+
14
+
15
+ [build-system]
16
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
17
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,6 @@
1
+ from .main import gen, seed
2
+
3
+ __all__ = [
4
+ "gen",
5
+ "seed"
6
+ ]
@@ -0,0 +1,55 @@
1
+ import random
2
+ import string
3
+ from typing import Optional
4
+
5
+ # random value generator
6
+ RNG = random.Random()
7
+
8
+ # set seed for random generator
9
+ def seed(value:int):
10
+ RNG.seed(value)
11
+
12
+ def gen(length:int, rng:Optional[random.Random]=None):
13
+ """
14
+ Generate a random string of specified length containing lowercase letters, uppercase letters and numbers
15
+
16
+ Parameters:
17
+ length (int): The length of the string to be generated, must be a positive integer
18
+
19
+ Returns:
20
+ str: Randomly generated string
21
+
22
+ Raises:
23
+ ValueError: Raised when the length is not a positive integer
24
+ """
25
+ # Validate input parameter legality
26
+ if not isinstance(length, int) or length <= 0:
27
+ raise ValueError("String length must be a positive integer greater than 0")
28
+
29
+ if rng is None: # use default
30
+ rng = RNG
31
+
32
+ # type of rng should be verified
33
+ if not isinstance(rng, random.Random):
34
+ raise TypeError()
35
+
36
+ # Build character pool: lowercase letters + uppercase letters + digits
37
+ char_pool = string.ascii_lowercase + string.ascii_uppercase + string.digits
38
+
39
+ # Randomly select specified number of characters from the character pool and concatenate into a string
40
+ random_chars = [rng.choice(char_pool) for _ in range(length)]
41
+ random_string = ''.join(random_chars)
42
+
43
+ return random_string
44
+
45
+ # Test examples
46
+ if __name__ == "__main__":
47
+ # set seed for generator
48
+ seed(42)
49
+
50
+ # Generate random string with length 8
51
+ print("Random string of length 8:", gen(8))
52
+ # Generate random string with length 16
53
+ print("Random string of length 16:", gen(16))
54
+ # Generate random string with length 20
55
+ print("Random string of length 20:", gen(20))