hashing a small number to a random looking 64 bit integer

前端 未结 4 713
臣服心动
臣服心动 2021-01-12 16:54

I am looking for a hash-function which operates on a small integer (say in the range 0...1000) and outputs a 64 bit int.

The result-set should look like a random dis

4条回答
  •  半阙折子戏
    2021-01-12 17:37

    Given: input i in the range of 0 to 1,000.

    const MaxInt which is the maximum value that cna be contained in a 64 bit int. (you did not say if it is signed or unsigned; 2^64 = 18446744073709551616 )

    and a function rand() that returns a value between 0 and 1 (most languages have such a function)

    compute hashvalue = i * rand() * ( MaxInt / 1000 )

提交回复
热议问题