Treasure chests

Hi, I couldnt find this topic here and anywhere else so I hope you dont mind my maybe stupid question :))
How in fight chests work? Is it random what rarity you get or is there a way to affect it during the fight to get rarer one?

Thanks, have a nice day :))

Welcome to the Com!

Even if it seems like an important visualization, these appearing stars on the left are just the shown rng when it comes to chest rarities.