Skip to content

Instantly share code, notes, and snippets.

@jin10086
Last active August 15, 2019 05:01
Show Gist options
  • Save jin10086/71bf21a6bc7bd866c17ca537caa8fd2f to your computer and use it in GitHub Desktop.
Save jin10086/71bf21a6bc7bd866c17ca537caa8fd2f to your computer and use it in GitHub Desktop.
import hashlib
def get_winner(min_n, max_n, num_win, key):
res = key
winners = set()
while len(winners) < num_win:
res = hashlib.sha256(res.encode("utf8")).hexdigest()
winners.add(int(res, 16) % (max_n - min_n + 1) + min_n)
return winners
if __name__ == "__main__":
key = "00000000000000000006a4d492b3a4dcf63a0786900060e73d12e5bb30c4bc4d"
print(get_winner(0, 113, 3, key))
#{113, 50, 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment