Randomize is don't work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Inferalo

I want to create a random dungeon generation, and I noticed that randi(), rand_range() and randi_range() always return the same numbers. For example: if I use var x = randi() % 15 it’s always return a 8.
I had used randomize() before this in _ready() function. And I have Ubuntu 21.04

Godot version 3.2.2.stable.official

Godot 3.2.x is not supported anymore. Please upgrade to 3.3.2 :slight_smile:

Calinou | 2021-08-04 17:52

I had updated to 3.3.2 and problem is still

Inferalo | 2021-08-05 06:17

var rng = RandomNumberGenerator.new()

func _ready():
    rng.randomize()
    for i in range(10):
        var _x = randi() % 15
        print(_x)

Everytime different number. Godot 3.3.2

anuke | 2021-08-05 11:18

I created a test project, added a node 2d and paste your code. Every time I run the program I have the same numbers:14, 0, 12, 0, 4,12, 8, 3, 3, 2
Maybe it’s problem with my Ubuntu?

Inferalo | 2021-08-05 11:54

var _x = rng.randi() % 15

Instead of

var _x = randi() % 15

My mistake

anuke | 2021-08-05 12:07

it helped, thanks!

Inferalo | 2021-08-05 12:17