public static void Main()
const int DIGITS_BEFORE_COMPLEX_RANDOM = 9;
long unixMs = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
double differenceBetweenMinAndMax = 12860928449;
int power = (int)Math.Ceiling(Math.Log10(differenceBetweenMinAndMax));
if (differenceBetweenMinAndMax / Math.Pow(10, power) == 1)
Console.WriteLine("Possible Range: " + differenceBetweenMinAndMax);
Console.WriteLine("Num digits before we only apply random to the left most digits of this length: " + DIGITS_BEFORE_COMPLEX_RANDOM);
Console.WriteLine("Power for base 10: " + power);
if (power > DIGITS_BEFORE_COMPLEX_RANDOM)
long unixMsSwapped = MakeUnixTimestampSignificant(unixMs, DIGITS_BEFORE_COMPLEX_RANDOM);
double divisor = Math.Pow(10, power - DIGITS_BEFORE_COMPLEX_RANDOM);
double toRandom = Math.Floor(differenceBetweenMinAndMax / divisor);
double randomed = unixMsSwapped % (long)toRandom;
double finalVal = randomed * divisor;
string toSwap = unixMs.ToString();
Console.WriteLine("Max amount possible to add to Min: " + differenceBetweenMinAndMax);
Console.WriteLine("Num to divide by: " + divisor);
Console.WriteLine("Num to random after dividing: " + toRandom);
Console.WriteLine("Randomed Number: " + randomed);
Console.WriteLine("Num after multiplying by the previous divisor: " + finalVal);
long unixMsSwapped = MakeUnixTimestampSignificant(unixMs, power);
double finalVal = unixMsSwapped % differenceBetweenMinAndMax;
Console.WriteLine("Randomed Number with full precision: " + finalVal);
static long MakeUnixTimestampSignificant(long ms, int significantDigits)
if (significantDigits <= 4)
StringBuilder swapper = new StringBuilder(ms.ToString());
int maxIndex = swapper.Length - significantDigits;
char first = swapper[swapper.Length - 1];
char second = swapper[swapper.Length - 2];
swapper[swapper.Length - 1] = swapper[maxIndex];
swapper[swapper.Length - 2] = swapper[maxIndex + 1];
swapper[maxIndex] = first;
swapper[maxIndex + 1] = second;
Console.WriteLine("Timestamp Before Swap = " + ms);
Console.WriteLine("Timestamp After Swap = " + swapper.ToString());
return long.Parse(swapper.ToString());