0 votes

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

in Engine by (174 points)

1 Answer

0 votes

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.

by (91 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.