Random
Randomness in an Intelligent Contract should use seeded random values because getting random data in the deterministic part may be difficult. Delegating randomness to a non-deterministic block can cause the contract to either never agree on that block or to trust the leader.
Seed acquisition methods
- Use some field of
message - Use current time (transaction time)
- Use
stdin, as shown below
def get_random_seed() -> bytes:
import os
import hashlib
f = os.fdopen(0, 'rb', buffering=0, closefd=False)
f.seek(0)
hash_obj = hashlib.sha256()
while True:
chunk = f.read(8192)
if not chunk:
return hash_obj.digest()
hash_obj.update(chunk)