Intelligent Contracts
Feature List
Random

Random

Getting random in deterministic part may be difficult. Trying to delegate it to non-deterministic block will cause your contract to either never agree on that block or to trust the leader. For that reason it is advised to use seeded random.

Seed acquisition methods

  1. Use some field of message
  2. Use current time (transaction time)
  3. 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)