Bitcoin Forum
November 24, 2026, 09:03:38 PM *
News: Latest Bitcoin Core release: 32.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: What are the flaws in this method of generating random numbers.  (Read 127 times)
memehunter (OP)
Legendary
*
Offline

Activity: 840
Merit: 1158


dubito, ergo cogito, ergo sum.


View Profile
December 30, 2024, 01:18:41 PM
 #1

So long story short it started with a giveaway topic where I suggested some improvements regarding verifiability. I want to ask if this process is robust or if I am missing something.


Thanks for the quick reply.
Do not get me wrong it is your give away and you have every right to do it your way but still, I want to suggest something which will boost the transparency of randomly selecting winners. It is better to go with a pre-announced block on any blockchain as it will eliminate any doubt (I don't have any Grin).
For example, you can in a hypothetical scenario keep randomizing till winners of your choice come out.
Thanks again for conducting such a giveaway hope you will acknowledge my humble advice.  


No worries, I appreciate your feedback Smiley

Now you mentioned it, I did remember seeing this a long time ago but it never came to me. Any idea on how does one get it setup?

Simply, you can set a pre-announced date and time and take the last two numbers of the nearest block hash. If you want multiple winners (numbers) take the nearest multiple blocks after the pre-announced date and time.
If the nature of the giveaway is as if you can not pre-announce the date and time (you are waiting for slots to fill) then take the nearest block after the exact time of booking the last slot.
For example; I want to select 3 winners out of 99 at 16:00 IST, 27/12/2024, here are the nearest block hashes  after 16:00 IST, 27/12/2024
0000000000000000000164eb3258ef63258ad338b3547601ae762b76cd1272f6
000000000000000000021b41a6dc87c59e94210451589a0ab29f5e6acbc1fead
00000000000000000000ec0188e6c7bd837edab275e3389842755b9101787ebc
Since I have to take the last two numerical digits (you have to pre-announce this as well) of each block, here are the winners, 26, 61, and 87.



▄▄███████████████████▄▄
▄███████████████████████▄
███████████████████▄█████
█████████████████████████
███████████▀█████████████
█████████▀███▀██████▀████
██████████████████▄██████
█████████▄▄█▄▄███████████
██████████▄▄▄████████████
███████████████████▀█████
████████████████▀▀███████
▀███████████████████████▀
▀▀███████████████████▀▀
 
 EARNBET 
|⚽ 🏀
 
🏈 🏓
 
🎯 🥊
 
⚾ 🎾
 
⛳ 🏐
 
🏏 🏎️
|


███████▄▄███████████
████▄██████████████████
██▄▀▀███████████████▀▀███
█▄████████████████████████
▄▄████████▀▀▀▀▀████████▄▄██
███████████████████████████
█████████▌████▀████████████
███████████████████████████
▀▀███████▄▄▄▄▄█████████▀▀██
█▀█████████████████████▀██
██▀▄▄███████████████▄▄███
████▀██████████████████
███████▀▀███████████

....HIGHEST....
VIP REWARDS

 ✔ G U A R A N T E E D  
| 
 🜲 
KING OF
THE CASTLE

$200K in prizes
| 
..PLAY NOW..
ThewsyRum
Newbie
*
Offline

Activity: 13
Merit: 1


View Profile
December 30, 2024, 04:21:55 PM
 #2

The entropy is low; using only the last two numeric digits provides only 100 possible outcomes. This limited range increases the likelihood of participants predicting the result, especially on a large scale
pooya87
Legendary
*
Offline

Activity: 4284
Merit: 12811



View Profile
December 31, 2024, 05:21:04 AM
Merited by ABCbits (4)
 #3

It works but a better way that also makes cheating (by both sides) much harder is this:
1. Server chooses a random entropy and keeps it private.
Code:
ServerSeed = ?
2. Server releases the hash of that entropy (so that server can not change the seed later, also SHA256 is used because in step 5 we use SHA512)
Code:
SHA256: cf4ff8d8e6915d752aff0878ccd3a53bda3456d75e636ba9fe95572ac2ea1913
3. One or more future block heights is chosen and announced as the additional entropy to be used.
Code:
876582, 876583, 876584
4. The list of participants is locked with each one having an index (from 0 to max count -1)
Code:
0. Foo
1. Bar
...
19. Baz
5. The algorithm to derive the result is publishes (the steps here).

[Now that everything is locked and can not change, we wait for the blocks to be mined]

6. Compute HMACSHA512 using the 3 block hashes (concatenated) and the actual seed from step 1 as the key to derive a 512-bit entropy.
Code:
HMACSHA512(block876582 | block876583 | block876584, key=ServerSeed) = 38f6ce46c9fbfeff669c7656883f2eb7a23a3b96d8a6d5ae278ba1939d4abf9722c12bdda04c72cd8c0633c7da89636d4171d9b670a60c7ca6bf7a6dac4bea09
7. Server publishes the entropy/seed from step 1 for everyone to verify
Code:
ServerSeed = 02236c4098bbddbc84aca10a3aac3f514a38a549632a159298e0944e8373cd58
8. Select bits from step 6 to get your integers. Something like this:
Code:
int max = 20
winner #1 = 0x38 % max = 16
winner #2 = 0xf6 % max = 6
winner #3 = 0xce % max = 6  reject as duplicate
winner #3 = 0x46 % max = 10

Step 6 and 8 can be changed to use a different KDF that derives keys and converts them to integers in a loop, but the basic idea of it is what I described here.

▄▄████████████████████▄▄
▄███████▀▀██████▀▀███████▄
█████▀██████████████▀█████
████████▄▄██████▄▄████▀███

██████████████████████████
██▄▄██████████████▄▄██████
██▀▀██████████████████▄▄██
██████▀▀██████████████▀▀██
██████████████████████████
███▄████▀▀██████▀▀████████
█████▄██████████████▄█████
▀███████▄▄██████▄▄███████▀
▀▀████████████████████▀▀
 
 DΞX.fo 
▄▄██████
█████████
██████████
██████████
██████████
█████████
▀▀██████

▄███████
▄██████████
████████████
█████████████
█████████████
|
▄▄█
▄████▀
▄███▀█▄
▄██▀█▄██
█████▀▀█
████████
████████
▀██▄████
▄████▄▄█
▄█████▀███
▄█████▀████▀
█████▀███████
▀██▀█████████
|..BTC......XMR...
..USDT.....LTC...
....Fees  0.8%.....
memehunter (OP)
Legendary
*
Offline

Activity: 840
Merit: 1158


dubito, ergo cogito, ergo sum.


View Profile
December 31, 2024, 08:02:47 AM
 #4

It works but a better way that also makes cheating (by both sides) much harder is this:
1. Server chooses a random entropy and keeps it private.
Code:
ServerSeed = ?
2. Server releases the hash of that entropy (so that server can not change the seed later, also SHA256 is used because in step 5 we use SHA512)
Code:
SHA256: cf4ff8d8e6915d752aff0878ccd3a53bda3456d75e636ba9fe95572ac2ea1913
3. One or more future block heights is chosen and announced as the additional entropy to be used.
Code:
876582, 876583, 876584
4. The list of participants is locked with each one having an index (from 0 to max count -1)
Code:
0. Foo
1. Bar
...
19. Baz
5. The algorithm to derive the result is publishes (the steps here).

[Now that everything is locked and can not change, we wait for the blocks to be mined]

6. Compute HMACSHA512 using the 3 block hashes (concatenated) and the actual seed from step 1 as the key to derive a 512-bit entropy.
Code:
HMACSHA512(block876582 | block876583 | block876584, key=ServerSeed) = 38f6ce46c9fbfeff669c7656883f2eb7a23a3b96d8a6d5ae278ba1939d4abf9722c12bdda04c72cd8c0633c7da89636d4171d9b670a60c7ca6bf7a6dac4bea09
7. Server publishes the entropy/seed from step 1 for everyone to verify
Code:
ServerSeed = 02236c4098bbddbc84aca10a3aac3f514a38a549632a159298e0944e8373cd58
8. Select bits from step 6 to get your integers. Something like this:
Code:
int max = 20
winner #1 = 0x38 % max = 16
winner #2 = 0xf6 % max = 6
winner #3 = 0xce % max = 6  reject as duplicate
winner #3 = 0x46 % max = 10

Step 6 and 8 can be changed to use a different KDF that derives keys and converts them to integers in a loop, but the basic idea of it is what I described here.

Thanks a lot for explaining it in such a detailed manner to a curious noob like me. I get that increasing entropy injects more randomness into the process as you and @ThewsyRum pointed out.
It is a great learning for me. Thanks once again.

Locking this topic as I get what I wanted and keeping this short and straight for anyone interested.



▄▄███████████████████▄▄
▄███████████████████████▄
███████████████████▄█████
█████████████████████████
███████████▀█████████████
█████████▀███▀██████▀████
██████████████████▄██████
█████████▄▄█▄▄███████████
██████████▄▄▄████████████
███████████████████▀█████
████████████████▀▀███████
▀███████████████████████▀
▀▀███████████████████▀▀
 
 EARNBET 
|⚽ 🏀
 
🏈 🏓
 
🎯 🥊
 
⚾ 🎾
 
⛳ 🏐
 
🏏 🏎️
|


███████▄▄███████████
████▄██████████████████
██▄▀▀███████████████▀▀███
█▄████████████████████████
▄▄████████▀▀▀▀▀████████▄▄██
███████████████████████████
█████████▌████▀████████████
███████████████████████████
▀▀███████▄▄▄▄▄█████████▀▀██
█▀█████████████████████▀██
██▀▄▄███████████████▄▄███
████▀██████████████████
███████▀▀███████████

....HIGHEST....
VIP REWARDS

 ✔ G U A R A N T E E D  
| 
 🜲 
KING OF
THE CASTLE

$200K in prizes
| 
..PLAY NOW..
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!