Let's say there are numbers - user id. It is required for each id to generate a (pseudo) random number in the specified range (eg, 1 - 32). Given that there should be a variation depending on the id of the users, even if they differ by one. With the same id, the same number must always be returned. In this case, I would like to achieve adequate entropy.

Clearly:

function getNumber(id, range = 32) { // ... return result } getNumber(123) // Например, 31 getnumber(124) // Например, 5 getNumber(123) // Снова, например, 31 

What are the fastest algorithms to solve this problem?

  • only 32 users? :) - Grundy
  • Random pull? - MihailPw
  • @Grundy is not her, for different id users the same numbers can be generated, the main thing is that they were in the established range - Vasya Shmarovoz
  • 3
    Take any hash function and the remainder of dividing by 32. - Alexey Ten
  • @ AGS17 Random will not create a situation that with the same id the same number will be generated - Vasya Shmarovoz

0