I was tasked with animating a random coin flip with the intention to be more interesting and scalable than a standard UI implementation. A random number is generated using squirrel noise* then transformed into a Boolean value using mod2 == 1, I also wrote an overload so it can act more like UI if prefered. This boolean is then sent to the shader where a heads or tails texture is sampled on the "top" face (that lands facing upwards) and the other on the bottom face. I chose to sample both textures so if the player looks closely then can see both heads and tails while the coin is flipping and to avoid loading and unloading textures which may cause the texture to change abruptly at a more noticeable time.
The two textures are only changed at the apex of the flip, when the coin is spinning fastest, concealing the change to players. The same principles can be used for other objects like dice, only choosing one face and changing the remaining 3 visible faces so no duplicate faces are shown.
The coin was originally animated on the shader but variances in spawn times made this unpredictable and reduced scalability. I considered a bone animation but decided against it as it would only work for one mesh and updating the mesh would be much more complex. I instead used a code based animation, which can be iterated on quickly or allow for multiple variants to avoid repetition.
*This white noise function was introduced to me via a GDC talk and had already been implemented (see my Github) in this project via a singleton so felt more appropriate. This also made the code more scalable since a weight can be assigned.