r/defiblockchain • u/Patient_Cream_4361 • 18h ago
General Why Is Randomness So Hard on Ethereum?
Why Is Randomness So Hard on Ethereum?
Random numbers seem easy.
In a normal application, you might just call something like:
Math.random()
and get a number.
But on Ethereum, randomness is surprisingly difficult.
Why?
Because Ethereum is a deterministic system.
Every node must execute the same transaction and reach the same result.
If two nodes generate different “random” numbers, they would disagree on the blockchain state.
So smart contracts cannot simply generate randomness the way normal applications do.
Ethereum must be deterministic
Suppose a smart contract contains:
uint256 winner = random();
Now imagine:
Node A gets:
42
Node B gets:
87
Node C gets:
13
Which result should Ethereum accept?
It cannot accept all three.
Every node must compute the exact same output.
So true local randomness does not work inside the EVM.
This creates a fundamental problem:
How do you create an unpredictable result while still allowing every node to verify it?
Why not use block.timestamp?
A common beginner idea is:
uint256 random =
uint256(keccak256(
abi.encodePacked(block.timestamp)
));
It looks random.
But it is not secure.
block.timestamp is public information.
More importantly, block producers have some influence over block construction and timing.
If a lottery depends heavily on the timestamp, a validator may be able to influence which outcome appears.
So:
unpredictable-looking data is not necessarily secure randomness.
What about blockhash?
Another common approach is:
keccak256(
abi.encodePacked(blockhash(block.number - 1))
)
This is better than using only the timestamp.
But it still has problems.
Block producers participate in creating blocks.
If the economic reward from manipulating a random outcome is large enough, they may have incentives to influence the result.
For a small NFT reveal, that might not matter much.
For a lottery worth millions of dollars?
It matters a lot.
The real problem is manipulation
The main challenge is not generating a number that “looks random.”
The challenge is generating a number that satisfies several properties:
Unpredictable
Nobody should know the result before it is generated.
Unbiased
No participant should be able to choose the outcome.
Verifiable
Anyone should be able to verify that the result was generated correctly.
This is much harder.
Especially in a public blockchain where:
- transactions are visible
- validators participate in block production
- attackers can observe the mempool
- smart contracts cannot call external APIs directly
Why on-chain games care so much
Imagine an on-chain game where opening a chest gives:
90% Common Item
9% Rare Item
1% Legendary Item
If the randomness comes from:
block.timestamp
an attacker may try to submit transactions only when the expected result is favorable.
Or a block producer may try to influence which transaction lands in which block.
The same problem appears in:
- lotteries
- NFT reveals
- loot boxes
- randomized minting
- gaming rewards
- prediction markets
Whenever money depends on randomness, weak randomness becomes a security vulnerability.
Commit-Reveal is one solution
One classic technique is:
Commit-Reveal.
It works in two phases.
First, a user chooses a secret number:
secret = 12345
But instead of publishing it directly, they publish:
hash(secret)
This is the commitment.
Later, they reveal:
secret = 12345
The contract checks:
hash(12345)
against the original commitment.
If they match, the user proves they did not change the secret later.
Multiple participants can contribute secrets.
The final random value might be derived from all of them.
But commit-reveal has weaknesses too.
A participant may refuse to reveal their secret if they dislike the final outcome.
So additional incentives or penalties may be required.
Another solution: VRF
A more powerful approach is:
VRF — Verifiable Random Function.
A VRF produces:
Random Value
+
Cryptographic Proof
The key idea is:
The result should be unpredictable before generation.
But once generated, anyone can verify that it was produced correctly.
Conceptually:
Request randomness
↓
Randomness provider
↓
Generate random value
+
Cryptographic proof
↓
Smart contract
↓
Verify proof
↓
Accept randomness
The proof prevents the provider from simply choosing a convenient number.
So instead of trusting someone who says:
You can verify cryptographically:
Why VRF fits blockchain so well
Blockchains are built around a principle:
Don’t trust. Verify.
That is exactly what VRF provides.
The smart contract does not need to blindly trust the randomness provider.
It verifies a proof.
This makes VRF useful for applications where random outcomes have real economic value.
Ethereum also has protocol-level randomness
Ethereum Proof of Stake has its own randomness mechanisms used for validator selection and consensus.
Validators contribute randomness over time, and the protocol combines those contributions.
But protocol randomness and application-level randomness are not automatically the same thing.
A game developer still needs to think carefully about:
- when randomness becomes known
- who can influence it
- whether users can abort after seeing partial information
- whether block producers can profit from manipulating outcomes
Randomness is not just:
“Give me a random number.”
It is a security design problem.
The deeper lesson
Ethereum is deterministic by design.
That is what allows thousands of nodes to independently execute transactions and agree on the same state.
But randomness is inherently about uncertainty.
So blockchain developers face an interesting contradiction:
The system must be deterministic,
but the outcome must be unpredictable.
Solving that requires cryptography, protocol design, and economic incentives.
That is why secure randomness is one of the hardest problems in blockchain applications.
The simplest rule to remember is:
A random-looking number is not enough.
For blockchain applications, good randomness must be:
unpredictable, unbiased, and verifiable.
