// Project: XnaShooter, File: RandomHelper.cs // Namespace: XnaShooter.Helpers, Class: RandomHelper // Path: C:\code\XnaShooter\Helpers, Author: Abi // Code lines: 113, Size of file: 3,24 KB // Creation date: 07.09.2006 05:56 // Last modified: 16.10.2006 11:27 // Generated with Commenter by abi.exDream.com #region Using directives using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; using System.Text; #endregion namespace XnaShooter.Helpers { /// /// Random helper /// public class RandomHelper { #region Variables /// /// Global random generator /// public static Random globalRandomGenerator = GenerateNewRandomGenerator(); #endregion #region Generate a new random generator /// /// Generate a new random generator with help of /// WindowsHelper.GetPerformanceCounter. /// Also used for all GetRandom methods here. /// /// Random public static Random GenerateNewRandomGenerator() { globalRandomGenerator = new Random((int)DateTime.Now.Ticks); //needs Interop: (int)WindowsHelper.GetPerformanceCounter()); return globalRandomGenerator; } // GenerateNewRandomGenerator() #endregion #region Get random float and byte methods /// /// Get random int /// /// Maximum /// Int public static int GetRandomInt(int max) { return globalRandomGenerator.Next(max); } // GetRandomInt(max) /// /// Get random float between min and max /// /// Min /// Max /// Float public static float GetRandomFloat(float min, float max) { return (float)globalRandomGenerator.NextDouble() * (max - min) + min; } // GetRandomFloat(min, max) /// /// Get random byte between min and max /// /// Min /// Max /// Byte public static byte GetRandomByte(byte min, byte max) { return (byte)(globalRandomGenerator.Next(min, max)); } // GetRandomByte(min, max) /// /// Get random Vector2 /// /// Minimum for each component /// Maximum for each component /// Vector2 public static Vector2 GetRandomVector2(float min, float max) { return new Vector2( GetRandomFloat(min, max), GetRandomFloat(min, max)); } // GetRandomVector2(min, max) /// /// Get random Vector3 /// /// Minimum for each component /// Maximum for each component /// Vector3 public static Vector3 GetRandomVector3(float min, float max) { return new Vector3( GetRandomFloat(min, max), GetRandomFloat(min, max), GetRandomFloat(min, max)); } // GetRandomVector3(min, max) /// /// Get random color /// /// Color public static Color GetRandomColor() { return new Color(new Vector3( GetRandomFloat(0.25f, 1.0f), GetRandomFloat(0.25f, 1.0f), GetRandomFloat(0.25f, 1.0f))); } // GetRandomColor() #endregion } // class RandomHelper } // namespace XnaShooter.Helpers