How to randomize text and show it in label?

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

Hello,
i have a question How to randomize text and show it in label? Like i am doing game with roles, and i need that there will be an same amount of roles like:
1.Big thumb man
2. killers

  1. Canadian
  2. Normal man

    Do you know how do i do it?
    (It will be multiplayer (lan) so if like that)
:bust_in_silhouette: Reply From: godot_dev_

If I understand, you have a list of potential labels to display and you want to display one of them randomly?

If so, define a list of your strings to display

var strList = ["str1","str2","str3"]

Then select a random index

#define a RNG variable
var rng = RandomNumberGenerator.new()

#genreate time-based seed, otherwise the same random sequence of 
#test will always be shown
rng.randomize()

#generate a randon integer to be used as an index
var ix = rng.randi_range(0,strList.size()-1)	
var randomStr  = strList[ix]

Now, assuming your label node is referenced by the myLabel variable, simply do

myLabel.text =randomStr