---
title: "Random"
description: "Random in Intelligent Contracts uses seeded randomness to avoid nondeterministic disagreement or leader trust."
source: https://docs.genlayer.com/developers/intelligent-contracts/features/random
last_updated: 2026-06-11
---

# 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

1. Use some field of `message`
2. Use current time (transaction time)
3. Use `stdin`, as shown below

```python3
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)
```
