#region usings
using System;
using System.Collections.Generic;
#endregion
namespace SM.Base.Utility
{
///
/// A global helper class for randomization.
///
public static class Randomize
{
///
/// The randomizer.
///
public static Random Randomizer = new Random();
///
/// Sets the seed for the randomizer.
///
/// The specified seed.
public static void SetSeed(int seed)
{
Randomizer = new Random(seed);
}
///
/// Generates a double and checks if its under the tolerance.
///
public static bool GetBool(float tolerance)
{
return Randomizer.NextDouble() < tolerance;
}
///
/// Generates a integer.
///
public static int GetInt()
{
return Randomizer.Next();
}
///
/// Generates a integer with a maximum.
///
public static int GetInt(int max)
{
return Randomizer.Next(max);
}
///
/// Generates a integer with a minimum and maximum
///
public static int GetInt(int min, int max)
{
return Randomizer.Next(min, max);
}
///
/// Generates a float between 0 and 1.
///
public static float GetFloat()
{
return (float) Randomizer.NextDouble();
}
///
/// Generates a float between 0 and the specified maximum.
///
public static float GetFloat(float max)
{
return (float) Randomizer.NextDouble() * max;
}
///
/// Generates a float between the specified minimum and the specified maximum.
///
public static float GetFloat(float min, float max)
{
return (float) Randomizer.NextDouble() * (max - min) + min;
}
///
/// Gets a random item from the provided list.
///
public static TSource GetRandomItem(this IList list)
{
return list[GetInt(0, list.Count - 1)];
}
}
}