I fixed the code, but also changed a few things such as %player% to %player's uuid% so if a player changes their name it stays, and added a cooldown to the command. Wasnt sure why you had the "wait 1 tick" but i deleted it, if it was there for a purpose you can just put it back in.
every 5 seconds:
loop all players:
if {%loop-player's uuid%.random} is not set:
give loop-player a random element of all items
command /toggle:
cooldown: 2 seconds
cooldown message: &cYou can not do this for another %remaining%&c. This is to avoid command spam.
trigger:
if {%player's uuid%.random} is not set:
set {%player's uuid%.random} to false
message "&7You have disabled random items." to player
else:
delete {%player's uuid%.random}
message "&7You have enabled random items." to player