using System;
using System.Collections.Generic;

namespace OctreeRendering
{
    static class RandomHelper
    {
        public static Random Random { get; private set; }

        static RandomHelper()
        {
            Random = new Random();
        }

        public static bool Probability(double p)
        {
            return p >= Random.NextDouble();
        }

        public static int Sign()
        {
            return Probability(0.5) ? -1 : 1;
        }

        public static float Centered(double distance)
        {
            return (float)((Random.NextDouble() - 0.5) * distance * 2);
        }
        public static float Centered(double distance, double around)
        {
            return (float)((Random.NextDouble() - 0.5) * distance * 2 + around);
        }

        public static float Between(double min, double max)
        {
            return (float)(Random.NextDouble() * (max - min) + min);
        }

        public static T InList<T>(List<T> list) where T : class
        {
            return list.Count == 0 ? null : list[Random.Next(list.Count)];
        }
    }
}
