public void Multithreaded() { var seq = new SpreadIntSequence(); var memory = new ConcurrentDictionary <uint, int>(); var tasks = new Task[16]; for (var t = 0; t < tasks.Length; t++) { tasks[t] = Task.Run(delegate { for (var i = 0; i < 256; i++) { var key = seq.Next(); memory.AddOrUpdate(key, 1, (key, oldValue) => oldValue + 1); } }); } foreach (var task in tasks) { task.Wait(); } foreach (var mem in memory) { Assert.Equal(1, mem.Value); } }
public void AsNumber() { var seq = new SpreadIntSequence(0); Assert.Equal(0x9E3779B1U, seq.Next()); Assert.Equal(0x3C6EF362U, seq.Next()); Assert.Equal(0xDAA66D13U, seq.Next()); Assert.Equal(0x78DDE6C4U, seq.Next()); Assert.Equal(0x17156075U, seq.Next()); Assert.Equal(0xB54CDA26U, seq.Next()); Assert.Equal(0x538453D7U, seq.Next()); Assert.Equal(0xF1BBCD88U, seq.Next()); Assert.Equal(0x8FF34739U, seq.Next()); Assert.Equal(0x2E2AC0EAU, seq.Next()); Assert.Equal(0xCC623A9BU, seq.Next()); Assert.Equal(0x6A99B44CU, seq.Next()); Assert.Equal(0x08D12DFDU, seq.Next()); }