-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Auto-generated __init__.py | ||
|
||
from . import hash_seed | ||
|
||
__all__ = ['hash_seed'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import hashlib | ||
|
||
def hash_to_seed(input_string): | ||
""" | ||
Hash a string into a small integer seed less than 500. | ||
Parameters: | ||
input_string (str): The string to hash. | ||
Returns: | ||
int: A seed value (0 <= seed < 500). | ||
""" | ||
# Ensure the input is a string | ||
input_string = str(input_string) | ||
|
||
# Create a SHA-256 hash of the string | ||
hash_object = hashlib.sha256(input_string.encode()) | ||
|
||
# Convert the hash to an integer | ||
large_number = int.from_bytes(hash_object.digest(), 'big') | ||
|
||
# Reduce the number to a value less than 500 | ||
small_seed = large_number % 500 | ||
|
||
return small_seed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters