分库分表算法
主要采用Hash,代码如下:
static void Main(string[] args) { string s = DateTime.Now.ToString("yyyMMddHHmmssfff"); string orderNo = $"Hash{s}001"; int tableSize = 32; SHA1 sha = new SHA1CryptoServiceProvider(); byte[] bytes = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(orderNo)); long l = BitConverter.ToUInt32(bytes); Console.WriteLine(orderNo); Console.WriteLine(l); Console.WriteLine(l % tableSize); Console.ReadKey(); }