My random number generator doesn't work

Hi, I'm making a datapack for minecraft java edition version 1.19.3 which uses a random number generator to generate either the number 0 or 1, then write a message to chat if the number is 0, or a different message if the number is 1. (Also, before all of this, it gives all players the speed effect). The commands are shown below:



scoreboard objectives add RandomNum dummy

summon minecraft:area_effect_cloud ~ ~ ~ {CustomName:"{\"text\":\"NAME1\"}",Duration:100,Particle:"underwater"}
tag @e[name=NAME1] add HasRandomNum
scoreboard players set @e[tag=HasRandomNum] RandomNum 0

summon minecraft:area_effect_cloud ~ ~ ~ {CustomName:"{\"text\":\"NAME2\"}",Duration:100,Particle:"underwater"}
tag @e[name=NAME2] add HasRandomNum1
scoreboard players set @e[tag=HasRandomNum1] RandomNum 1


scoreboard objectives add FinalRandomNum dummy

summon minecraft:area_effect_cloud ~ ~ ~ {CustomName:"{\"text\":\"NAME3\"}",Duration:100,Particle:"underwater"}
tag @e[name=NAME3] add HasRandomNum2
execute as @e[tag=HasRandomNum2] run scoreboard players operation @s FinalRandomNum = @e[tag=HasRandomNum,tag=HasRandomNum1,limit=1,sort=random] RandomNum

execute if score @e[name=NAME3,limit=1] FinalRandomNum matches 0 run tellraw @a {"text":"The number is 0"}
execute if score @e[name=NAME3,limit=1] FinalRandomNum matches 1 run tellraw @a {"text":"The number is 1"}

(Note: these commands are in my tick.mcfunction file)

When i open a world with my datapack in it and type /reload, I receive the speed effect, which tells me there probably aren't any syntax errors in the commands, but no messages are written to chat. What have i done wrong?

Continue to help post