Hello Kind People!

I couldn't figure out this by myself yet: How to randomize an array of numbers?

I want to make a simple quiz game, that has 3 answer buttons, but there will be only 1 correct answer, and 2 wrong answer.

And I want to randomize the order of the buttons for every new game start, so the correct buttons position can't be memorized.

How should I do this? How to randomize the order of the buttons?

Thank you for your help, and have a nice day!

Regards, NOIZ Ctrl

PS. I tried to randomize an array of numbers, and remove the randomized number from the array every time, but I haven't had any success.

I've created this function some time ago:

static func shuffle_array(array):
	randomize() 
	var size = array.size()
	var i = 0
	for item in array:
		var temp = array[i]
		var random_index = rand_range(i, size)
		array[i] = array[random_index]
		array[random_index] = temp
		i += 1

With that, you can put your buttons on an array and shuffle them :)

Thank you very much for your help, and example code!

I haven't find anything on this "random-button-order" topic anywhere in Google, and here in the Godot forums neither, and even StackOverflow, they just voted me down and told me to "be more specific" or something like that.. gahh.. :D

I highly appreciate help especially with examples like yours!

Thank you again! (I might come back later, if I stuck with something, I'm going to try to wrap my head around your code first :) I'm just a hobbist)

6 years later