Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't restore RNG state properly #44031

Closed
timothyqiu opened this issue Dec 2, 2020 · 3 comments · Fixed by #44089
Closed

Can't restore RNG state properly #44031

timothyqiu opened this issue Dec 2, 2020 · 3 comments · Fixed by #44089
Milestone

Comments

@timothyqiu
Copy link
Member

Godot version: 3.2.3 & current master (ba51af7)

OS/device including version: not graphics-related.

Issue description:

RNG state is not restored after calling RandomNumberGenerator.set_seed with a seed saved from RandomNumberGenerator.get_seed.

The issue is caused by get_seed returning the current RNG state, while set_seed takes a seed, not state.

PR #35764 tries to resolve this problem by making the interface more intuitive, but seems inactive.

PR #27171 introduced this behavior.

A workaround is, maybe, reseeding manually after generating a number, sacrificing randomness.

Steps to reproduce:

Run the following script with Godot.

extends SceneTree


func _init():
	var rng = RandomNumberGenerator.new()

	# let the seed change
	rng.randomize()
	rng.randi()
	rng.randi()

	var saved = rng.seed
	print('Current seed: ', saved)

	print('This seed produces:')
	print(rng.randf())
	print(rng.randf())

	rng.seed = saved
	print('Resetting the seed produces:')
	print(rng.randf())
	print(rng.randf())

Actual output:

Current seed: 8670679328791200068
This seed produces:
0.823806
0.514134
Resetting the seed produces:
0.028601
0.02974

Expected output:

Current seed: 8670679328791200068
This seed produces:
0.823806
0.514134
Resetting the seed produces:
0.823806
0.514134

Minimal reproduction project: N/A

@ghost
Copy link

ghost commented Dec 2, 2020

PR #27171 introduced this behavior.

I thought that was reverted. b5d9099

@timothyqiu
Copy link
Member Author

It's only reverted on the 3.1 branch. 😂

@ghost
Copy link

ghost commented Dec 2, 2020

Oh right, it was left in the master, and 3.2 was the master back then. Yeah, reverting it solves the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants