你应该使用 Random 类。
// Make one instance of random, the seed is the milliseconds, other way random always returns the same sequence of random numbers.
static readonly Random rnd = new Random(DateTime.Nom.Milliseconds);
List<Sprite> Sprites = new List<Sprite>(50);
public void Update()
{
//Add new sprites with a 90% or probability
if (Sprites.Count<50 && rnd.Next(100) > 90)
{
Sprite sprite = new Sprite();
// This X calculation makes the sprite not to get out of the screen at both sides
sprite.Pos.X = (float) ( (0.1f + 0.8f * rnd.NextDouble()) * GraphicsDevice.Viewport.Width);
sprite.Pos.Y = (float) ( rnd.NextDouble() * 300 );
Sprites.Add(Sprite);
}
}
当然 de Sprite 类取决于你.. :)