public void Multithreaded() { var seq = new SpreadShortSequence(); var memory = new ConcurrentDictionary <ushort, 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 NonRepeat() { var seq = new SpreadShortSequence(); var memory = new byte[65536]; for (var i = 0; i < 65536; i++) { var value = seq.Next(); memory[value]++; } foreach (var mem in memory) { Assert.Equal(1, mem); } }
public void AsNumber() { var seq = new SpreadShortSequence(0); Assert.Equal(0x9E33, seq.Next()); Assert.Equal(0x3C66, seq.Next()); Assert.Equal(0xDA99, seq.Next()); Assert.Equal(0x78CC, seq.Next()); Assert.Equal(0x16FF, seq.Next()); Assert.Equal(0xB532, seq.Next()); Assert.Equal(0x5365, seq.Next()); Assert.Equal(0xF198, seq.Next()); Assert.Equal(0x8FCB, seq.Next()); Assert.Equal(0x2DFE, seq.Next()); Assert.Equal(0xCC31, seq.Next()); Assert.Equal(0x6A64, seq.Next()); Assert.Equal(0x0897, seq.Next()); }