Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hashlib
- class CustomPRNG:
- def __init__(self, seed=None):
- if seed is None:
- seed = self._generate_seed()
- self.state = seed
- def _generate_seed(self):
- return hashlib.sha256(str(hash(time.time())).encode()).digest()
- def _hash_state(self):
- return hashlib.sha256(self.state).digest()
- def random(self):
- # Use the current state as the seed for the next state
- self.state = self._hash_state()
- # Convert the hashed state to a float in the range [0, 1)
- return int.from_bytes(self.state, byteorder='big') / (2**256)
- # Usage
- prng = CustomPRNG()
- for _ in range(10):
- print(prng.random())
Advertisement
Comments
-
- This is a custom-prng provides the foundation ready to be used for a prototype - testing chain commonly implemented using a linked list. Where a linkedlist contains the data from an initliaze seed. Note it is not complete
Add Comment
Please, Sign In to add comment
Advertisement