Skip to main content

Command Palette

Search for a command to run...

A simple and authentic online lucky draw

Cryptographic hash and salt from future signal

Updated
1 min read
A simple and authentic online lucky draw
H

Just run the code, or yourself.

Application senario

We want to organize an online lucky draw on social media. Users who post photos with a certain hash tags can join the lucky draw. The questions is, how to conduct a fair and authentic lucky draw?

One can do a live stream and incorporate some real time signals (e.g. TV new in backdrop) to show the audience of the process. However, this is resource consuming.

We want to do a simple random choice from a list of names. The result needs to depend on a signal that is publicly accessible and verifiable. One method is to use a cryptographic hash function to generate this random number given a salt from public future signal.

The code

Here is the reference implementation:

import hashlib

# Modify this to be real list of users
ls = '''
user 1
user 2
user 3
'''

# Modify this to incorporate a future signal
salt = '43'

a = [x for x in ls.split('\n') if x]
l = len(a)
print(a, l)
s = ''.join(a) + salt
print(s)
r = hashlib.sha256(s.encode('utf-8'))
h = r.hexdigest()
i = int(h, 16)
print(i)
print(i % l)
print(a[i % l])

In our lucky draw, we selected the two digits after decimal point of BitCoin USD closing price of 10pm-11pm trading window, using coinmarketcap as the source of truth.

N

Hello everyone, If you're having issues withdrawing, swapping, or selling ETHM (EthereumMeta), LUSD, Thoreum V3, 4WMM, BTCBR, or any other tokens, we can help.
Many projects experience migration errors, liquidity loss, or contract issues that lock funds. Whether it's meme coins, DeFi tokens, or abandoned projects, our team specializes in recovering inaccessible assets.
For secure assistance, contact us at: email📩rexasfinance99@gmail.com