I have the following function:
long Foo (long min, long max)
{
ulong range = max - min; // guaranteed to fit in ulong
ulong x = GenerateRandomULongBetween0AndRange(range);
return x + min; // result is guaranteed to fit in long
}
But the C# compiler says I cannot add ulong and long. x can be greater than long.MaxValue though, and min may be negative. So I can't cast one to the other. How to proceed? :-(