using System.Security.Cryptography;
public static void Main()
long contractId = 11607410420840;
long hash = HashFromLong(contractId);
var bucketId = ModuloBucketOfLongHash(hash, count, from);
Console.WriteLine(bucketId);
public static long HashFromLong(long input)
Span<byte> buf = stackalloc byte[sizeof(long)];
bool written = BitConverter.TryWriteBytes(buf, input);
Span<byte> result = stackalloc byte[SHA256.HashSizeInBytes];
bool hashed = SHA256.TryHashData(source: buf, destination: result, out _);
return BitConverter.ToInt64(result);
public static long ModuloBucketOfLongHash(long hash, long сount, long fromId)
long result = hash % сount + fromId;