Skip to content

Instantly share code, notes, and snippets.

@fuqunaga
Last active December 24, 2015 09:22
Show Gist options
  • Save fuqunaga/83bc7d964f40cb5eebea to your computer and use it in GitHub Desktop.
Save fuqunaga/83bc7d964f40cb5eebea to your computer and use it in GitHub Desktop.
[System.Serializable]
public class RandFloat : Rand<float>
{
public RandFloat(float min, float max) : base(min, max){ }
protected override float _rand(float min, float max) { return UnityEngine.Random.Range(min, max); }
}
[System.Serializable]
public class RandInt : Rand<int>
{
public RandInt(int min, int max) : base(min, max){ }
protected override int _rand(int min, int max) { return UnityEngine.Random.Range(min, max+1); }
}
public abstract class Rand<T> where T: struct
{
public T _min;
public T _max;
T? _value;
public T value { get { return _value ?? Calc(); } }
public Rand() { }
public Rand(T min, T max) { _min = min; _max = max; }
public T Calc()
{
_value = _rand(_min, _max);
return _value.Value;
}
protected abstract T _rand(T min, T max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment