Linting rules
E024: random-requires-initialization
Requires random generator initialization before random value generation calls.
Metadata
Code:E024Rule:random-requires-initializationStatus: Preview sincev0.0.1Quick fix: sometimes available
What it does
Requires random generator initialization before random value generation calls.
Why is this bad?
Calling random.uint256(...) or random.range(...) before
random.initialize(...) / random.initializeBy(...) can lead to predictable
or invalid randomness behavior.
Example
fun main() {
val x = random.uint256();}Use instead:
fun main() {
random.initializeBy(123);
val x = random.uint256();
}Behavior notes
This check is control-flow aware. It does not just scan text for "init before use".
It builds a control-flow graph (CFG) and verifies that for each
random.uint256(...) / random.range(...) call, initialization is guaranteed
on all reachable execution paths before that call.
It also follows function calls, so helper functions that initialize random are taken into account.
Source codeLast updated on