← Pixel Dreamer Studio

Make a seed repeat: daily runs, replays and roguelike seeds

seed() sets the one random sequence that randi(), randf() and every script share. Anything else that draws from it shifts your results. Give the system its own RandomNumberGenerator.

Create var rng := RandomNumberGenerator.new(), set rng.seed, and roll with rng.randi_range() instead of the global randi_range(). In our Godot 4.7 test a three-reel slot rolled with seed(1124) gave the same 1000 spins twice. Adding a screen shake that called randf_range() twice per spin left only 5 of 1000 spins the same, different from the second spin on. A shake only on three of a kind broke it from the fourth spin. Its own RandomNumberGenerator, seeded 1124, gave 1000 of 1000 the same while the shake and other randi() calls ran.

The code

Save it as run_rng.gd. make() returns a RandomNumberGenerator with your seed, or a random one for 0. daily_seed() turns a date string into a seed, so every player gets the same run that day. save() and load_state() store and restore where the sequence is, so a loaded game rolls exactly what it would have. For example: const RunRng := preload("res://run_rng.gd"), var rng := RunRng.make(RunRng.daily_seed(Time.get_date_string_from_system())), then rng.randi_range(0, 5) for every roll that must repeat.

extends RefCounted
## Give a system (slot machine, loot table, map generator) its own random numbers,
## so a seed gives the same results whatever else in the game uses random.


static func make(seed_value: int = 0) -> RandomNumberGenerator:
	var r := RandomNumberGenerator.new()
	if seed_value != 0:
		r.seed = seed_value
	else:
		r.randomize()  # 0 = a different run every time
	return r


static func daily_seed(date_text: String) -> int:
	return hash(date_text)  # the same text gives the same seed, for example "2026-11-27"


static func save(r: RandomNumberGenerator) -> int:
	return r.state  # store it with the save file


static func load_state(r: RandomNumberGenerator, saved_state: int) -> void:
	r.state = saved_state  # the run continues exactly where it was saved

What we measured

A spin was three reels, each a number from 0 to 5. We rolled 1000 spins and compared them spin by spin with a first run. The shake called randf_range() twice, as a screen shake or a particle burst might. Two runs gave the same numbers, apart from the generators made without a seed, which are meant to differ.

Why it happens

randi(), randf(), randi_range() and the others all read from one random sequence shared by every script, and seed() only sets where it starts. Each call moves it on, so any other code that uses random between your rolls, a screen shake, a particle color, an enemy's idle timer, takes numbers your rolls would have had, and everything after shifts. A RandomNumberGenerator is a separate sequence that only your code moves.

What to change

A slot machine built this way: Slot Roguelike Kit for Godot 4 rolls from a symbol bag with its own RandomNumberGenerator. Set Rng Seed in the Inspector, or machine.rng.seed in code, for the same results every run, or pass a grid to spin() to force a result for a tutorial or a rigged first spin.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Slot Roguelike Kit for Godot 4 rolls from a symbol bag with its own RandomNumberGenerator: set its seed for daily runs and replays, or force any result.

More how-tos: Game systems