ad-supermath 0.1.0__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.
- ad_supermath-0.1.0/LICENSE +9 -0
- ad_supermath-0.1.0/PKG-INFO +100 -0
- ad_supermath-0.1.0/README.md +89 -0
- ad_supermath-0.1.0/ad_supermath.egg-info/PKG-INFO +100 -0
- ad_supermath-0.1.0/ad_supermath.egg-info/SOURCES.txt +14 -0
- ad_supermath-0.1.0/ad_supermath.egg-info/dependency_links.txt +1 -0
- ad_supermath-0.1.0/ad_supermath.egg-info/top_level.txt +1 -0
- ad_supermath-0.1.0/pyproject.toml +13 -0
- ad_supermath-0.1.0/setup.cfg +4 -0
- ad_supermath-0.1.0/setup.py +12 -0
- ad_supermath-0.1.0/supermath/__init__.py +6 -0
- ad_supermath-0.1.0/supermath/basic.py +72 -0
- ad_supermath-0.1.0/supermath/finance.py +63 -0
- ad_supermath-0.1.0/supermath/geometry.py +51 -0
- ad_supermath-0.1.0/supermath/random_utils.py +66 -0
- ad_supermath-0.1.0/supermath/statistics.py +46 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yashvi Harsora
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files to deal in the Software
|
|
7
|
+
without restriction.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ad-supermath
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A custom Python math utility library
|
|
5
|
+
Author: Yashvi Harsora
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
Dynamic: requires-python
|
|
11
|
+
|
|
12
|
+
# SuperMath 📊
|
|
13
|
+
|
|
14
|
+
SuperMath is a custom Python utility library that provides useful mathematical, statistical, geometry, finance, and random utility functions in one place.
|
|
15
|
+
|
|
16
|
+
It is designed to make common calculations easier and more accessible for developers, students, and data enthusiasts.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
SuperMath includes multiple modules:
|
|
23
|
+
|
|
24
|
+
### Basic Utilities
|
|
25
|
+
|
|
26
|
+
- percentage
|
|
27
|
+
- average
|
|
28
|
+
- square
|
|
29
|
+
- cube
|
|
30
|
+
- factorial
|
|
31
|
+
- gcd
|
|
32
|
+
- lcm
|
|
33
|
+
- map_range
|
|
34
|
+
- normalize
|
|
35
|
+
- round_to
|
|
36
|
+
- sign
|
|
37
|
+
- swap
|
|
38
|
+
|
|
39
|
+
### Statistics
|
|
40
|
+
|
|
41
|
+
- mean
|
|
42
|
+
- median
|
|
43
|
+
- mode
|
|
44
|
+
- data_range
|
|
45
|
+
- variance
|
|
46
|
+
- standard_deviation
|
|
47
|
+
- percentile
|
|
48
|
+
|
|
49
|
+
### Geometry
|
|
50
|
+
|
|
51
|
+
- circle_area
|
|
52
|
+
- circle_circumference
|
|
53
|
+
- rectangle_area
|
|
54
|
+
- rectangle_perimeter
|
|
55
|
+
- triangle_area
|
|
56
|
+
- triangle_perimeter
|
|
57
|
+
- square_area
|
|
58
|
+
- square_perimeter
|
|
59
|
+
- cylinder_volume
|
|
60
|
+
- sphere_volume
|
|
61
|
+
- sphere_surface_area
|
|
62
|
+
- distance
|
|
63
|
+
|
|
64
|
+
### Finance
|
|
65
|
+
|
|
66
|
+
- simple_interest
|
|
67
|
+
- compound_interest
|
|
68
|
+
- compound_amount
|
|
69
|
+
- profit
|
|
70
|
+
- loss
|
|
71
|
+
- profit_percentage
|
|
72
|
+
- loss_percentage
|
|
73
|
+
- discount_amount
|
|
74
|
+
- discounted_price
|
|
75
|
+
- gst_amount
|
|
76
|
+
- price_with_gst
|
|
77
|
+
- emi
|
|
78
|
+
|
|
79
|
+
### Random Utilities
|
|
80
|
+
|
|
81
|
+
- random_int
|
|
82
|
+
- random_float
|
|
83
|
+
- random_float_range
|
|
84
|
+
- random_choice
|
|
85
|
+
- shuffle_list
|
|
86
|
+
- random_bool
|
|
87
|
+
- random_char
|
|
88
|
+
- random_digit
|
|
89
|
+
- random_string
|
|
90
|
+
- random_password
|
|
91
|
+
- random_color
|
|
92
|
+
- random_sample
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Installation
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install supermath
|
|
100
|
+
```
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# SuperMath 📊
|
|
2
|
+
|
|
3
|
+
SuperMath is a custom Python utility library that provides useful mathematical, statistical, geometry, finance, and random utility functions in one place.
|
|
4
|
+
|
|
5
|
+
It is designed to make common calculations easier and more accessible for developers, students, and data enthusiasts.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
SuperMath includes multiple modules:
|
|
12
|
+
|
|
13
|
+
### Basic Utilities
|
|
14
|
+
|
|
15
|
+
- percentage
|
|
16
|
+
- average
|
|
17
|
+
- square
|
|
18
|
+
- cube
|
|
19
|
+
- factorial
|
|
20
|
+
- gcd
|
|
21
|
+
- lcm
|
|
22
|
+
- map_range
|
|
23
|
+
- normalize
|
|
24
|
+
- round_to
|
|
25
|
+
- sign
|
|
26
|
+
- swap
|
|
27
|
+
|
|
28
|
+
### Statistics
|
|
29
|
+
|
|
30
|
+
- mean
|
|
31
|
+
- median
|
|
32
|
+
- mode
|
|
33
|
+
- data_range
|
|
34
|
+
- variance
|
|
35
|
+
- standard_deviation
|
|
36
|
+
- percentile
|
|
37
|
+
|
|
38
|
+
### Geometry
|
|
39
|
+
|
|
40
|
+
- circle_area
|
|
41
|
+
- circle_circumference
|
|
42
|
+
- rectangle_area
|
|
43
|
+
- rectangle_perimeter
|
|
44
|
+
- triangle_area
|
|
45
|
+
- triangle_perimeter
|
|
46
|
+
- square_area
|
|
47
|
+
- square_perimeter
|
|
48
|
+
- cylinder_volume
|
|
49
|
+
- sphere_volume
|
|
50
|
+
- sphere_surface_area
|
|
51
|
+
- distance
|
|
52
|
+
|
|
53
|
+
### Finance
|
|
54
|
+
|
|
55
|
+
- simple_interest
|
|
56
|
+
- compound_interest
|
|
57
|
+
- compound_amount
|
|
58
|
+
- profit
|
|
59
|
+
- loss
|
|
60
|
+
- profit_percentage
|
|
61
|
+
- loss_percentage
|
|
62
|
+
- discount_amount
|
|
63
|
+
- discounted_price
|
|
64
|
+
- gst_amount
|
|
65
|
+
- price_with_gst
|
|
66
|
+
- emi
|
|
67
|
+
|
|
68
|
+
### Random Utilities
|
|
69
|
+
|
|
70
|
+
- random_int
|
|
71
|
+
- random_float
|
|
72
|
+
- random_float_range
|
|
73
|
+
- random_choice
|
|
74
|
+
- shuffle_list
|
|
75
|
+
- random_bool
|
|
76
|
+
- random_char
|
|
77
|
+
- random_digit
|
|
78
|
+
- random_string
|
|
79
|
+
- random_password
|
|
80
|
+
- random_color
|
|
81
|
+
- random_sample
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install supermath
|
|
89
|
+
```
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ad-supermath
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A custom Python math utility library
|
|
5
|
+
Author: Yashvi Harsora
|
|
6
|
+
Requires-Python: >=3.7
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
Dynamic: requires-python
|
|
11
|
+
|
|
12
|
+
# SuperMath 📊
|
|
13
|
+
|
|
14
|
+
SuperMath is a custom Python utility library that provides useful mathematical, statistical, geometry, finance, and random utility functions in one place.
|
|
15
|
+
|
|
16
|
+
It is designed to make common calculations easier and more accessible for developers, students, and data enthusiasts.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
SuperMath includes multiple modules:
|
|
23
|
+
|
|
24
|
+
### Basic Utilities
|
|
25
|
+
|
|
26
|
+
- percentage
|
|
27
|
+
- average
|
|
28
|
+
- square
|
|
29
|
+
- cube
|
|
30
|
+
- factorial
|
|
31
|
+
- gcd
|
|
32
|
+
- lcm
|
|
33
|
+
- map_range
|
|
34
|
+
- normalize
|
|
35
|
+
- round_to
|
|
36
|
+
- sign
|
|
37
|
+
- swap
|
|
38
|
+
|
|
39
|
+
### Statistics
|
|
40
|
+
|
|
41
|
+
- mean
|
|
42
|
+
- median
|
|
43
|
+
- mode
|
|
44
|
+
- data_range
|
|
45
|
+
- variance
|
|
46
|
+
- standard_deviation
|
|
47
|
+
- percentile
|
|
48
|
+
|
|
49
|
+
### Geometry
|
|
50
|
+
|
|
51
|
+
- circle_area
|
|
52
|
+
- circle_circumference
|
|
53
|
+
- rectangle_area
|
|
54
|
+
- rectangle_perimeter
|
|
55
|
+
- triangle_area
|
|
56
|
+
- triangle_perimeter
|
|
57
|
+
- square_area
|
|
58
|
+
- square_perimeter
|
|
59
|
+
- cylinder_volume
|
|
60
|
+
- sphere_volume
|
|
61
|
+
- sphere_surface_area
|
|
62
|
+
- distance
|
|
63
|
+
|
|
64
|
+
### Finance
|
|
65
|
+
|
|
66
|
+
- simple_interest
|
|
67
|
+
- compound_interest
|
|
68
|
+
- compound_amount
|
|
69
|
+
- profit
|
|
70
|
+
- loss
|
|
71
|
+
- profit_percentage
|
|
72
|
+
- loss_percentage
|
|
73
|
+
- discount_amount
|
|
74
|
+
- discounted_price
|
|
75
|
+
- gst_amount
|
|
76
|
+
- price_with_gst
|
|
77
|
+
- emi
|
|
78
|
+
|
|
79
|
+
### Random Utilities
|
|
80
|
+
|
|
81
|
+
- random_int
|
|
82
|
+
- random_float
|
|
83
|
+
- random_float_range
|
|
84
|
+
- random_choice
|
|
85
|
+
- shuffle_list
|
|
86
|
+
- random_bool
|
|
87
|
+
- random_char
|
|
88
|
+
- random_digit
|
|
89
|
+
- random_string
|
|
90
|
+
- random_password
|
|
91
|
+
- random_color
|
|
92
|
+
- random_sample
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Installation
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install supermath
|
|
100
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
ad_supermath.egg-info/PKG-INFO
|
|
6
|
+
ad_supermath.egg-info/SOURCES.txt
|
|
7
|
+
ad_supermath.egg-info/dependency_links.txt
|
|
8
|
+
ad_supermath.egg-info/top_level.txt
|
|
9
|
+
supermath/__init__.py
|
|
10
|
+
supermath/basic.py
|
|
11
|
+
supermath/finance.py
|
|
12
|
+
supermath/geometry.py
|
|
13
|
+
supermath/random_utils.py
|
|
14
|
+
supermath/statistics.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
supermath
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ad-supermath"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A custom Python math utility library"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name="Yashvi Harsora" }
|
|
11
|
+
]
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.7"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="ad-supermath",
|
|
5
|
+
version="0.1.0",
|
|
6
|
+
description="A custom Python math utility library with statistics, geometry, finance and random utilities",
|
|
7
|
+
author="Yashvi Harsora",
|
|
8
|
+
packages=find_packages(),
|
|
9
|
+
python_requires=">=3.7",
|
|
10
|
+
install_requires=[],
|
|
11
|
+
license="MIT"
|
|
12
|
+
)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Basic math utilities for SuperMath
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# 1. Calculate percentage
|
|
5
|
+
def percentage(value, total):
|
|
6
|
+
return (value / total) * 100
|
|
7
|
+
|
|
8
|
+
# 2. square
|
|
9
|
+
def square(x):
|
|
10
|
+
return x*x
|
|
11
|
+
|
|
12
|
+
# 3. cube
|
|
13
|
+
def cube(x):
|
|
14
|
+
return x*x*x
|
|
15
|
+
|
|
16
|
+
# 4. even numbers
|
|
17
|
+
def is_even(num):
|
|
18
|
+
return num%2==0
|
|
19
|
+
|
|
20
|
+
# 5. odd numbers
|
|
21
|
+
def is_odd(num):
|
|
22
|
+
return num%2!=0
|
|
23
|
+
|
|
24
|
+
# 6. Limit value
|
|
25
|
+
def clamp(value, min_value, max_value):
|
|
26
|
+
return max(min_value, min(value, max_value))
|
|
27
|
+
|
|
28
|
+
# 7. average
|
|
29
|
+
def average(numbers):
|
|
30
|
+
return sum(numbers) / len(numbers)
|
|
31
|
+
|
|
32
|
+
# 8. factorial
|
|
33
|
+
def factorial(n):
|
|
34
|
+
result = 1
|
|
35
|
+
for i in range(1, n + 1):
|
|
36
|
+
result *= i
|
|
37
|
+
return result
|
|
38
|
+
|
|
39
|
+
# 9. GCD (Greatest Common Divisor (Euclidean algorithm))
|
|
40
|
+
def gcd(a, b):
|
|
41
|
+
while b != 0:
|
|
42
|
+
a, b = b, a % b
|
|
43
|
+
return a
|
|
44
|
+
|
|
45
|
+
# 10. LCM (Least Common Multiple)
|
|
46
|
+
def lcm(a, b):
|
|
47
|
+
return abs(a * b) // gcd(a, b)
|
|
48
|
+
|
|
49
|
+
# 11. map-range (Map value from one range to another)
|
|
50
|
+
def map_range(value, in_min, in_max, out_min, out_max):
|
|
51
|
+
return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
|
|
52
|
+
|
|
53
|
+
# 12. normalized value (Normalize value between 0 and 1)
|
|
54
|
+
def normalize(value, min_val, max_val):
|
|
55
|
+
return (value - min_val) / (max_val - min_val)
|
|
56
|
+
|
|
57
|
+
# 13. round (Round number to given decimal places)
|
|
58
|
+
def round_to(value, decimals=0):
|
|
59
|
+
return round(value, decimals)
|
|
60
|
+
|
|
61
|
+
# 14. sign (check the sign of the number- positive/negative)
|
|
62
|
+
def sign(num):
|
|
63
|
+
if num > 0:
|
|
64
|
+
return 1
|
|
65
|
+
elif num < 0:
|
|
66
|
+
return -1
|
|
67
|
+
else:
|
|
68
|
+
return 0
|
|
69
|
+
|
|
70
|
+
# 15. swap (Swap two values)
|
|
71
|
+
def swap(a, b):
|
|
72
|
+
return b, a
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
# Finance utilities for SuperMath
|
|
4
|
+
|
|
5
|
+
# 1. Calculate simple interest
|
|
6
|
+
def simple_interest(principal, rate, time):
|
|
7
|
+
return (principal * rate * time) / 100
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# 2. Calculate compound interest
|
|
11
|
+
def compound_interest(principal, rate, time):
|
|
12
|
+
return principal * (1 + rate/100) ** time - principal
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# 3. Calculate total amount after compound interest
|
|
16
|
+
def compound_amount(principal, rate, time):
|
|
17
|
+
return principal * (1 + rate/100) ** time
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# 4. Calculate profit
|
|
21
|
+
def profit(cost_price, selling_price):
|
|
22
|
+
return selling_price - cost_price
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# 5. Calculate loss
|
|
26
|
+
def loss(cost_price, selling_price):
|
|
27
|
+
return cost_price - selling_price
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# 6. Calculate profit percentage
|
|
31
|
+
def profit_percentage(cost_price, selling_price):
|
|
32
|
+
return ((selling_price - cost_price) / cost_price) * 100
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# 7. Calculate loss percentage
|
|
36
|
+
def loss_percentage(cost_price, selling_price):
|
|
37
|
+
return ((cost_price - selling_price) / cost_price) * 100
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# 8. Calculate discount amount
|
|
41
|
+
def discount_amount(price, discount_percent):
|
|
42
|
+
return price * discount_percent / 100
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# 9. Calculate final price after discount
|
|
46
|
+
def discounted_price(price, discount_percent):
|
|
47
|
+
return price - (price * discount_percent / 100)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# 10. Calculate GST amount
|
|
51
|
+
def gst_amount(price, gst_percent):
|
|
52
|
+
return price * gst_percent / 100
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# 11. Calculate price including GST
|
|
56
|
+
def price_with_gst(price, gst_percent):
|
|
57
|
+
return price + (price * gst_percent / 100)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# 12. Calculate EMI (Equated Monthly Installment)
|
|
61
|
+
def emi(principal, annual_rate, months):
|
|
62
|
+
monthly_rate = annual_rate / (12 * 100)
|
|
63
|
+
return (principal * monthly_rate * (1 + monthly_rate) ** months) / ((1 + monthly_rate) ** months - 1)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
# Geometry utilities for SuperMath
|
|
4
|
+
|
|
5
|
+
# 1. Calculate area of circle
|
|
6
|
+
def circle_area(radius):
|
|
7
|
+
return math.pi * radius ** 2
|
|
8
|
+
|
|
9
|
+
# 2. Calculate circumference of circle
|
|
10
|
+
def circle_circumference(radius):
|
|
11
|
+
return 2 * math.pi * radius
|
|
12
|
+
|
|
13
|
+
# 3. Calculate rectangle area
|
|
14
|
+
def rectangle_area(length, width):
|
|
15
|
+
return length * width
|
|
16
|
+
|
|
17
|
+
# 4. Calculate rectangle perimeter
|
|
18
|
+
def rectangle_perimeter(length, width):
|
|
19
|
+
return 2 * (length + width)
|
|
20
|
+
|
|
21
|
+
# 5. Calculate triangle area
|
|
22
|
+
def triangle_area(base, height):
|
|
23
|
+
return 0.5 * base * height
|
|
24
|
+
|
|
25
|
+
# 6. Calculate triangle perimeter
|
|
26
|
+
def triangle_perimeter(a, b, c):
|
|
27
|
+
return a + b + c
|
|
28
|
+
|
|
29
|
+
# 7. Calculate square area
|
|
30
|
+
def square_area(side):
|
|
31
|
+
return side * side
|
|
32
|
+
|
|
33
|
+
# 8. Calculate square perimeter
|
|
34
|
+
def square_perimeter(side):
|
|
35
|
+
return 4 * side
|
|
36
|
+
|
|
37
|
+
# 9. Calculate cylinder volume
|
|
38
|
+
def cylinder_volume(radius, height):
|
|
39
|
+
return math.pi * radius ** 2 * height
|
|
40
|
+
|
|
41
|
+
# 10. Calculate sphere volume
|
|
42
|
+
def sphere_volume(radius):
|
|
43
|
+
return (4/3) * math.pi * radius ** 3
|
|
44
|
+
|
|
45
|
+
# 11. Calculate sphere surface area
|
|
46
|
+
def sphere_surface_area(radius):
|
|
47
|
+
return 4 * math.pi * radius ** 2
|
|
48
|
+
|
|
49
|
+
# 12. Distance between two points
|
|
50
|
+
def distance(x1, y1, x2, y2):
|
|
51
|
+
return math.sqrt((x2-x1)**2 + (y2-y1)**2)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import random
|
|
2
|
+
import string
|
|
3
|
+
|
|
4
|
+
# Random utilities for SuperMath
|
|
5
|
+
|
|
6
|
+
# 1. Generate random integer in range
|
|
7
|
+
def random_int(min_val, max_val):
|
|
8
|
+
return random.randint(min_val, max_val)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# 2. Generate random float between 0 and 1
|
|
12
|
+
def random_float():
|
|
13
|
+
return random.random()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# 3. Generate random float in range
|
|
17
|
+
def random_float_range(min_val, max_val):
|
|
18
|
+
return random.uniform(min_val, max_val)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# 4. Select random element from list
|
|
22
|
+
def random_choice(items):
|
|
23
|
+
return random.choice(items)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# 5. Shuffle a list
|
|
27
|
+
def shuffle_list(items):
|
|
28
|
+
random.shuffle(items)
|
|
29
|
+
return items
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# 6. Generate random boolean
|
|
33
|
+
def random_bool():
|
|
34
|
+
return random.choice([True, False])
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# 7. Generate random character
|
|
38
|
+
def random_char():
|
|
39
|
+
return random.choice(string.ascii_letters)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# 8. Generate random digit
|
|
43
|
+
def random_digit():
|
|
44
|
+
return random.choice(string.digits)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# 9. Generate random string
|
|
48
|
+
def random_string(length):
|
|
49
|
+
chars = string.ascii_letters + string.digits
|
|
50
|
+
return ''.join(random.choice(chars) for _ in range(length))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# 10. Generate random password
|
|
54
|
+
def random_password(length):
|
|
55
|
+
chars = string.ascii_letters + string.digits + "!@#$%^&*"
|
|
56
|
+
return ''.join(random.choice(chars) for _ in range(length))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# 11. Generate random color (hex)
|
|
60
|
+
def random_color():
|
|
61
|
+
return "#{:06x}".format(random.randint(0, 0xFFFFFF))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# 12. Randomly pick multiple items
|
|
65
|
+
def random_sample(items, count):
|
|
66
|
+
return random.sample(items, count)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Statistics utilities for SuperMath
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# 1. Calculate mean (average)
|
|
5
|
+
def mean(numbers):
|
|
6
|
+
return sum(numbers) / len(numbers)
|
|
7
|
+
|
|
8
|
+
# 2. Find median value
|
|
9
|
+
def median(numbers):
|
|
10
|
+
nums = sorted(numbers)
|
|
11
|
+
n = len(nums)
|
|
12
|
+
|
|
13
|
+
if n % 2 == 0:
|
|
14
|
+
return (nums[n//2 - 1] + nums[n//2]) / 2
|
|
15
|
+
else:
|
|
16
|
+
return nums[n//2]
|
|
17
|
+
|
|
18
|
+
# 3. Find mode (most frequent value)
|
|
19
|
+
|
|
20
|
+
def mode(numbers):
|
|
21
|
+
return max(set(numbers), key=numbers.count)
|
|
22
|
+
|
|
23
|
+
# 4. Find range of data
|
|
24
|
+
def data_range(numbers):
|
|
25
|
+
return max(numbers) - min(numbers)
|
|
26
|
+
|
|
27
|
+
# 5. Calculate variance
|
|
28
|
+
def variance(numbers):
|
|
29
|
+
m = mean(numbers)
|
|
30
|
+
return sum((x - m) ** 2 for x in numbers) / len(numbers)
|
|
31
|
+
|
|
32
|
+
# 6. Calculate standard deviation
|
|
33
|
+
def standard_deviation(numbers):
|
|
34
|
+
return variance(numbers) ** 0.5
|
|
35
|
+
|
|
36
|
+
# 7. Find percentile
|
|
37
|
+
def percentile(numbers, p):
|
|
38
|
+
nums = sorted(numbers)
|
|
39
|
+
k = (len(nums)-1) * (p/100)
|
|
40
|
+
f = int(k)
|
|
41
|
+
c = f + 1
|
|
42
|
+
|
|
43
|
+
if c >= len(nums):
|
|
44
|
+
return nums[f]
|
|
45
|
+
|
|
46
|
+
return nums[f] + (nums[c] - nums[f]) * (k - f)
|