godotengine / godotengine/godot-docs

RandomNumberGenerator - Could be clearer

Open
#4,271 1 comment 0 reactions 0 assignees View on GitHub
area:class reference enhancement
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

**Your Godot version:**
3.2.3

**Issue description:**
I created a small script that colourised sprites with random colours every second. Then I instanced the scene several times.
I was surprised to see that all of the instances were "randomised" to the same colour and kept the same colours.

This isn't the behaviour I expected by default, even having read the doc quickly.

It turns out that Godot has a specific default seed hard-coded (-6398989897141750821), whereas all the other languages I've used default to seeding using the current time.

```
extends Sprite

var randomage = RandomNumberGenerator.new()

func _process(delta):
cycle += delta

if cycle > 1:
print(self.get_path())
get_node("inner").modulate = Color(randomage.randf(), randomage.randf(), randomage.randf())
get_node("outer").modulate = Color(randomage.randf(), randomage.randf(), randomage.randf())
cycle = 0
```

Issues:
1) I get now that I can fix it with "randomage.randomize", but that's not clearly spelt out in the docs. The doc says "based on a time-dependent seed" in the example - but it's not clear what this means; I'm guessing it's the equiv of using Time.now().
2) I would suggest spelling out as an explicit note/warning that default random behaviour won't be as other languages by default due to the hard-coded seed.
3) "dependant" is misspelt (disclosure: I only noticed because my browser spellchecker pointed it out in this issue ;-) - it's actually a word I usually misspell myself!).
4) The randomize() method description is similarly unclear, and far too brief.
5) The randomize() method description is grammatically invalid.
6) randi_range() - it may be worth spelling out what the max/min values are given most folks don't know the 32bit int signed values off the tops of their heads.
7) avalanche effect - A clear, non-lingo explanation of what this is talking about would be useful. Also helpful would be a script example demonstrating how to get the "avalanche effect" rather than just saying to "use a hash function to improve seed quality".

**URL to the documentation page (if already existing):**
https://docs.godotengine.org/en/stable/classes/class_randomnumbergenerator.html#class-randomnumbergenerator-method-randomize

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.