How can i make that at least 3 vowels are generated?

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

Lettertile.gd code:

extends Node2D
class_name LetterTile

# Letter sprites by Kenney.nl
# https://opengameart.org/content/letter-tiles

var current_tile: int
var letter_value = ""
var letter_points = 0
var box_position: Vector2
signal tile_clicked

func _ready():
	hide()
	randomize()
	$HiddenTimer.wait_time = rand_range(0.0, 0.5)
	$HiddenTimer.start()
	current_tile = randi() % 26 # Chooses a number between 0-25. I want that at least 3 of the 16 times executed a vowel it's generated (10, 13, 15, 16 and 19). 
	letter_value = get_letter_value(current_tile)
	letter_points = get_points_value(current_tile)
	$Tiles.frame = current_tile

Main.gd code:

func spawn_new_letters():
	for i in range(4):
		for j in range(4):
			var tile:LetterTile = Letter.instance()
			$LetterBox.add_child(tile)
			# warning-ignore:return_value_discarded
			tile.connect("tile_clicked", self, "on_tile_clicked", [tile])
			tile.position = Vector2(i * TILESIZE, j * TILESIZE) + Vector2(4 * i, 4 * j)
			tile.box_position = tile.position

enter image description here

:bust_in_silhouette: Reply From: jgodfrey

Currently, when you instance a new letter, it’s free to randomly select any of the 26 items in your alphabet. Since there’s (currently) no way for the letter generation to be aware of what has / has not already been generated, it’s not possible to get the necessary mix of consonants and vowels.

Instead of letting LetterTile randomly decide what letter it represents, I’d change the code so that Main tells LetterTile what letter it will be. That simplifies the problem, because then Main can be in charge of the mix of consonants and vowels as it can have access to all of the chosen letters at the same time.

Regarding how to get Main to choose between consonants and vowels, there are lots of ways. One easy way might be to store the two letter types separately from each other. Then, you could choose from the set of vowels how ever many times you want, and then choose the remainder of the letters from the set of consonants.