questo è l'hash dell'ultimo blocco
00000000000000000000a4eb0e9b38a1fe159ac4b3a519c6c1ea5e60ab842332
come potremmo determinare i numeri vincenti
Puoi usare questo codice:
Provably fair giveaway manager
As the blockhash is just a number, its last 6 digits is converted to decimal using this function:
var decimal = parseInt(blockhash.slice(-6), 16);
Now we have an integer (0 to 16777215) from the blockhash.
After dividing this decimal by the number of participants, we use the modulo operator (%) to get the division remainder becomes the index_number.
This index_number is applied in the participants list, to get the position of the winner.
var index_number = decimal % competitors.length;
var winner = competitors[index_number];
For additional winners, the past winners are removed from the list and one more digit is added from the blockhash. A maximum 30 was added to avoid working with big numbers.
Sul forum credo sia abbastanza standard
Ho cercato di capire questo codice, e grazie anche a chat gpt abbiamo buttato giu un codice in python, che sembra funzionare :
def estrai_vincitori(hash_blocco, partecipanti, numero_vincitori=3):
vincitori = []
for i in range(numero_vincitori):
# Prendi gli ultimi 6 caratteri e ulteriori se ci sono più vincitori
hex_slice = hash_blocco[-(6 + i):len(hash_blocco) - i]
# Converti i caratteri in numero decimale
decimal = int(hex_slice, 16)
# Trova il vincitore con il modulo rispetto al numero di partecipanti
index_number = decimal % len(partecipanti)
vincitore = partecipanti[index_number]
vincitori.append(vincitore)
# Rimuovi il vincitore per evitare duplicati
partecipanti.pop(index_number)
return vincitori
# Inserisci l'hash e il numero di partecipanti
hash_blocco = input("Inserisci l'hash del blocco (64 caratteri esadecimali): ")
numero_partecipanti = int(input("Inserisci il numero di partecipanti: "))
# Crea una lista di partecipanti da 1 a numero_partecipanti
partecipanti = list(range(1, numero_partecipanti + 1))
# Estrai i vincitori
vincitori = estrai_vincitori(hash_blocco, partecipanti, 3)
# Stampa i vincitori
print("I vincitori sono:", vincitori)
Il programma da la possibilità di incollare l'hash selezionato dalla blocco, e inserire il numero di partecipanti. In base all'hash lui genera i tre vincitori