MultiversX Tracker is Live!

Random Enough?

Bitcoin Reddit

More / Bitcoin Reddit 100 Views

I'm not going to implement this for a wallet or anything, so don't worry about that (I'm just a guy who happens to like bitcoin and cpp and randomness all at the same time). I'm just curious if you all would consider this implementation of generating a random private key to have enough entropy to be considered secure. This is also tailored to those who know (hopefully more than me) about the standard cpp library <random>.

In this library is a "true random" feature called "random_device" which apparently pulls "random" data from within the machine that the code is run on... I couldn't find in the documentation specifically where this data is pulled (I'm assuming some hardware device that has noise or some unpredictable data when that hardware isn't being specifically used by any process or something, but this is kind of where my question and lack of knowledge arises). This "true random" number is then commonly used as the seed for another pseudo random function. Here is the most basic code implementation I could come up with using this to create a 64 character hex string of randomly selected hex characters:

#include <random> #include <string> #include <map> std::random_device rd; std::mt19937 mt(rd()); std::uniform_int_distribution<long> distHex(0, 15); std::map<int, char> hexMap = { {0, '0'}, {1, '1'}, {2, '2'}, {3, '3'}, {4, '4'}, {5, '5'}, {6, '6'}, {7, '7'}, {8, '8'}, {9, '9'}, {10, 'A'}, {11, 'B'}, {12, 'C'}, {13, 'D'}, {14, 'E'}, {15, 'F'} }; std::string hex64() { std::string hexString; for (int i = 0; i < 64; i++) { hexString += hexMap[distHex(mt)]; } return hexString; } int main() { std::cout << hex64() << std::endl; return 0; } 

This outputs something like this: 8b5e09d8ff2a58bc419559302ef0ac751506de4ae9d084eb0b4753ed7bfec5ba

Assuming this is run offline somewhere, what are your thoughts (maybe you have more insight to the "random_device" than me) on the entropy here? The security?

Edit: Code syntax

submitted by /u/zacguymarino
[link] [comments]
Get BONUS $200 for FREE!

You can get bonuses upto $100 FREE BONUS when you:
πŸ’° Install these recommended apps:
πŸ’² SocialGood - 100% Crypto Back on Everyday Shopping
πŸ’² xPortal - The DeFi For The Next Billion
πŸ’² CryptoTab Browser - Lightweight, fast, and ready to mine!
πŸ’° Register on these recommended exchanges:
🟑 Binance🟑 Bitfinex🟑 Bitmart🟑 Bittrex🟑 Bitget
🟑 CoinEx🟑 Crypto.com🟑 Gate.io🟑 Huobi🟑 Kucoin.



Comments