how to shuffle array by randomize() function?

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

var a = [1,2,3,4,5,6,7,8,9]

func _ready():
	randomize()
	for i in range(9):
		print(a[i])

this is not work shuffle.
how to use randomize?

Also, can randomize be done the same as the Fisher-Yates algorithm?

:bust_in_silhouette: Reply From: Dlean Jeans

You haven’t called shuffle():

randomize()
a.shuffle()
print(a)

Click here to run.

randomize() only randomizes the seed so it’s different every time.

thanks for comment.
it looks like i don’t need randomization if i use shuffle.

bgegg | 2019-07-07 09:27

i use randomize function when i use randi() function or rand_range() function.

bgegg | 2019-07-07 09:28