C Method for Generating Random Colors Based on XNA

  • 2021-06-28 09:39:22
  • OfStack

This article shows an example of how C#generates random colors based on XNA.Share it for your reference.Specific analysis is as follows:

Make sure you are using Microsoft.Xna.Framework.Graphics, in order to use the XNA Color class, and System for Random.

You can call a new random color: Color newColor= RandomColor();

The main code is as follows:


private Color RandomColor() 
{
 Random random = new Random(DateTime.Now.Millisecond); 
 byte r = (byte)random.Next(0, 255); 
 byte g = (byte)random.Next(0, 255); 
 byte b = (byte)random.Next(0, 255); 
 return new Color(r, g, b ); 
}

I hope that the description in this paper will be helpful to everyone's C#program design.


Related articles: