rand_range() not giving random results

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

HEY! i have a function trying to give a random number between 0 and the size on an array
for some reason it always prints out 39 (the array size is 64) here’s the code:

func gunspawner():
	for x in range(global.map_size.x):
		for y in range(global.map_size.y):
			if global.map[x][y] == global.EMPTY:
				available_slots_spawns.append([x,y])
	var choose_place = int(rand_range(0,available_slots_spawns.size()))
	print(choose_place)
	gun.position = Vector2(global.map_coord[available_slots_spawns[choose_place][0]][available_slots_spawns[choose_place][1]])
	add_child(gun)
	checkForWeapons()

thanks for taking the time to look at my code :slight_smile:
PLEASE HELP!!!

:bust_in_silhouette: Reply From: Cereyn555

Hi,

have you tried to call function randomize() in your _ready() function?

THANKS!! it worked perfectly

ROBOTOO007 | 2020-05-25 10:56