CSharp · Console
using System;
public class Program
{
public static void Main()
{
for (int i=0; i<15; i++) {
int tick = Environment.TickCount;
var r1 = new Random();
int tick2 = Environment.TickCount;
if (tick != tick2) {
// tick changed during new Random, try again
continue;
}
// r1 was init'd with known tick, make r2 the same
var r2 = new Random(tick);
// they should get same output then?
int num0 = r1.Next();
int num1 = r2.Next();
// both randoms seeded by same TickCount, should have same results????? Right????
if (num0 == num1) {
Console.WriteLine($"[{tick}] Same numbers: {num0}");
} else {
Console.WriteLine($"[{tick}] Numbers differ: {num0} != {num1}");
}
break;
}
}
}