method
Random.seed
Random.seed(value)
Sets the starting state of the random-number generator. Every subsequent call to Random.range and Random.chance then follows a fixed, repeatable sequence for that seed, so seeding with the same value makes two runs produce identical randomness — invaluable for tests, replays, and debugging. Seed once, typically in a Start-phase handler before you draw any random numbers. Use different seed values (for example a frame count or a level number) when you want variety between runs.
Parameters
valuethe seed; the same value reproduces the same sequenceExample
program ReproducibleField {
property Position { column: int = 0, row: int = 0 }
model Star { Position }
const GRID_WIDTH: int = 20
const GRID_HEIGHT: int = 15
const TILE_SIZE: int = 16
handler SeedField phase Start {
Random.seed(value: 42)
for spawn_index in 0 .. 8 {
spawn Star {
Position {
column: Random.range(low: 0, high: GRID_WIDTH - 1),
row: Random.range(low: 0, high: GRID_HEIGHT - 1)
}
}
}
}
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
for (Position) in query [Position, {Star}] {
Screen.fill_rectangle(
x: Position.column * TILE_SIZE,
y: Position.row * TILE_SIZE,
width: TILE_SIZE,
height: TILE_SIZE,
color: Color.White)
}
Screen.show()
}
}