Generate a random number without repeat the last one

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

Is it possible to generate a random number without repeat the last one that is picked?

Something like that:

The randi gives the options: 1,2,3,4,5,6,7,8,9,10;
than chosse number 9;
than randi gives the options: 1,2,3,4,5,6,7,8,10;
than choose number 5;
than randi givers 9 options: 1,2,3,4,6,7,8,9,10
than choose number 10;
than randi gives the options: 1,2,3,4,5,6,7,8,9

thanks guys

:bust_in_silhouette: Reply From: Alex Pires

Just press ENTER to remove a random item of your list.

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

var gob

func _ready():
	randomize()
	
func _process(delta):
	
	
	if Input.is_action_just_pressed("ui_accept"):
		gob = ns[randi()% ns.size()]
		ns.erase(gob)
		print("NS"+var2str(ns))
		print(gob)

When there is no more items to remove, will generate an error.