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

Add ability to restore RandomNumberGenerator state #45019

Merged
merged 1 commit into from
Jan 8, 2021
Merged

Add ability to restore RandomNumberGenerator state #45019

merged 1 commit into from
Jan 8, 2021

Conversation

Xrayez
Copy link
Contributor

@Xrayez Xrayez commented Jan 8, 2021

3.2 version of #44089.

get_seed() still returns the previous state and not the initial seed, because users may rely on this behavior for resetting the state in 3.2. Documented this is going to be fixed in 4.0.

func _ready():
	var rng = RandomNumberGenerator.new()
	var initial_state = rng.state
	print("Initial ", rng.state)
	print(rng.randf())
	print(rng.randf())
	print(rng.randf())
	print("Current ", rng.state)
	print("Reset to initial state...")
	rng.state = initial_state
	print(rng.randf())
	print(rng.randf())
	print(rng.randf())
	print("Current ", rng.state)
Initial -6332740101472756719
0.621225
0.978975
0.367289
Current -6028506256414837201
Reset to initial state...
0.621225
0.978975
0.367289
Current -6028506256414837201

3.2 version of b510771.

`get_seed()` still returns the previous state and not the initial seed,
because users may rely on this behavior for resetting the state in 3.2.
Documented this is going to be fixed in 4.0.

Co-authored-by: MidZik <matt.idzik1@gmail.com>
@Xrayez Xrayez requested a review from a team as a code owner January 8, 2021 13:05
@akien-mga akien-mga added this to the 3.2 milestone Jan 8, 2021
@akien-mga akien-mga merged commit ecf432a into godotengine:3.2 Jan 8, 2021
@akien-mga
Copy link
Member

Thanks!

@Xrayez Xrayez deleted the rng-state-3.2 branch January 8, 2021 14:33
@akien-mga akien-mga modified the milestones: 3.2, 3.3 Apr 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants