Weighted random probability With not reoccurance when needed more than 1 outcome

Question

Hi, I am trying to get random 3 result so basicly player will be able to choose from this 3 result. But when I run the code below sometimes same result can be shown. How can I make it so when A will be given and next time if its again A then program shoud do a re create random number until all 3 are unique.

extends Node

randomize()

``````for i in range(3):
print(get_item_rarity())
``````

func get_item_rarity():
var random_float = randf()

``````if random_float < 0.02:
return "A"
elif random_float < 0.13:
return "B"
elif random_float < 0.15:
return "C"
elif random_float < 0.26:
return "D"
elif random_float < 0.28:
return "E"
elif random_float < 0.39:
return "F"
elif random_float < 0.41:
return "G"
elif random_float < 0.52:
return "H"
elif random_float < 0.54:
return "I"
elif random_float < 0.64:
return "J"
elif random_float < 0.66:
return "K"
elif random_float < 0.68:
return "L"
elif random_float < 0.78:
return "M"
elif random_float < 0.80:
return "N"
elif random_float < 0.90:
return "O"
else:
return "P"
``````
• Store the last random letter in a global variable (a `var` outside of your function, let’s call it `last_random_letter`)
• In `func get_item_rarity()`, instead of directly returning a letter, store it in a variable and check if this letter is the same than `last_random_letter`. While they are equal, keep regenerating a random float and letter, until they stop being equal.

I am kind of new to whole programing. I understand what you mean but no idea how to execute it:D

If you make and index and store each resulting letter, then you can simply loop through and compare each letter, changing it if it’s the same as the previous one.