#region File Description
//-----------------------------------------------------------------------------
// RandomMath.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using Microsoft.Xna.Framework;
#endregion
namespace NetRumble
{
///
/// Static methods to assist with random-number generation.
///
static public class RandomMath
{
#region Random Singleton
///
/// The Random object used for all of the random calls.
///
private static Random random = new Random();
public static Random Random
{
get { return random; }
}
#endregion
#region Single Variations
///
/// Generate a random floating-point value between the minimum and
/// maximum values provided.
///
/// This is similar to the Random.Next method, substituting singles
/// for integers.
/// The minimum value.
/// The maximum value.
/// A random floating-point value between the minimum and maximum v
/// alues provided.
public static float RandomBetween(float minimum, float maximum)
{
return minimum + (float)random.NextDouble() * (maximum - minimum);
}
#endregion
#region Direction Generation
///
/// Generate a random direction vector.
///
/// A random direction vector in 2D space.
public static Vector2 RandomDirection()
{
float angle = RandomBetween(0, MathHelper.TwoPi);
return new Vector2((float)Math.Cos(angle),
(float)Math.Sin(angle));
}
///
/// Generate a random direction vector within constraints.
///
/// The minimum angle.
/// The maximum angle.
///
/// A random direction vector in 2D space, within the constraints.
///
public static Vector2 RandomDirection(float minimumAngle, float maximumAngle)
{
float angle = RandomBetween(MathHelper.ToRadians(minimumAngle),
MathHelper.ToRadians(maximumAngle)) - MathHelper.PiOver2;
return new Vector2((float)Math.Cos(angle),
(float)Math.Sin(angle));
}
#endregion
}
}