DRY: Implement GetRand using FastRandomContext::randrange
Summary:
Partial backport of Core PR14955
https://github.com/bitcoin/bitcoin/pull/14955/commits/152146e782d401aa1ce7d989d62306aabc85f22e
Depends on D4397
Test Plan:
make check ./bench/bench_bitcoin
Benchmark output:
Benchmark, evals, iterations, total, min, max, median AES128CBC_DecryptNoPad, 5, 200000, 7.80447, 7.45714e-06, 9.0949e-06, 7.47062e-06 AES128CBC_DecryptWithPad, 5, 200000, 8.09388, 7.42459e-06, 1.00658e-05, 7.61723e-06 AES128CBC_EncryptNoPad, 5, 200000, 7.24038, 7.12447e-06, 7.41962e-06, 7.20733e-06 AES128CBC_EncryptWithPad, 5, 200000, 8.41316, 7.89842e-06, 1.0065e-05, 8.01471e-06 AES128_Decrypt, 5, 800000, 7.20773, 1.77777e-06, 1.8538e-06, 1.78528e-06 AES128_Encrypt, 5, 800000, 7.69409, 1.70442e-06, 2.63127e-06, 1.78812e-06 AES256CBC_DecryptNoPad, 5, 160000, 7.63437, 9.51882e-06, 9.56835e-06, 9.54365e-06 AES256CBC_DecryptWithPad, 5, 160000, 8.12963, 9.51592e-06, 1.22456e-05, 9.56993e-06 AES256CBC_EncryptNoPad, 5, 160000, 7.60103, 9.26909e-06, 9.65623e-06, 9.62985e-06 AES256CBC_EncryptWithPad, 5, 160000, 8.2272, 1.01518e-05, 1.05889e-05, 1.0211e-05 AES256_Decrypt, 5, 640000, 5.77722, 1.77038e-06, 1.9195e-06, 1.7765e-06 AES256_Encrypt, 5, 640000, 5.46718, 1.70119e-06, 1.72318e-06, 1.70484e-06 Base58CheckEncode, 5, 320000, 3.41466, 2.09833e-06, 2.202e-06, 2.09946e-06 Base58Decode, 5, 800000, 3.58198, 8.95305e-07, 8.95759e-07, 8.95548e-07 Base58Encode, 5, 470000, 3.11644, 1.29798e-06, 1.42188e-06, 1.29987e-06 BenchLockedPool, 5, 530, 4.60588, 0.00173335, 0.00174617, 0.00173718 BnBExhaustion, 5, 650, 2.95366, 0.000891597, 0.000935362, 0.000893478 CCheckQueueSpeedPrevectorJob, 5, 1400, 4.30052, 0.000607875, 0.000628208, 0.000609534 CCoinsCaching, 5, 170000, 2.30147, 2.59715e-06, 2.78038e-06, 2.72892e-06 CashAddrDecode, 5, 800000, 3.35907, 8.21457e-07, 8.47788e-07, 8.46074e-07 CashAddrEncode, 5, 800000, 1.97135, 4.41679e-07, 6.53359e-07, 4.42229e-07 CoinSelection, 5, 650, 0.723561, 0.00021832, 0.000229857, 0.000219296 ConstructGCSFilter, 5, 1000, 7.79769, 0.00153385, 0.00156619, 0.00156602 DeserializeAndCheckBlockTest, 5, 160, 8.00376, 0.00997038, 0.010072, 0.00997738 DeserializeBlockTest, 5, 130, 3.10457, 0.00468373, 0.00492242, 0.00472969 FastRandom_1bit, 5, 440000000, 4.44635, 1.99112e-09, 2.077e-09, 1.99707e-09 FastRandom_32bit, 5, 110000000, 5.14621, 9.22211e-09, 9.58329e-09, 9.31103e-09 MatchGCSFilter, 5, 50000, 6.1511, 2.42759e-05, 2.5481e-05, 2.43115e-05 MempoolEviction, 5, 41000, 3.84048, 1.84281e-05, 1.93112e-05, 1.86376e-05 MerkleRoot, 5, 800, 26.229, 0.0064959, 0.00660377, 0.00656373 PrevectorClearNontrivial, 5, 28300, 9.51849, 6.4736e-05, 7.25892e-05, 6.67103e-05 PrevectorClearTrivial, 5, 88600, 16.9428, 3.77137e-05, 3.98922e-05, 3.7849e-05 PrevectorDeserializeNontrivial, 5, 6800, 2.71309, 7.69326e-05, 8.05378e-05, 8.05091e-05 PrevectorDeserializeTrivial, 5, 52000, 3.23929, 1.21703e-05, 1.27922e-05, 1.23203e-05 PrevectorDestructorNontrivial, 5, 28800, 9.71234, 6.57783e-05, 6.90784e-05, 6.75548e-05 PrevectorDestructorTrivial, 5, 88900, 5.48495, 1.1788e-05, 1.26339e-05, 1.25621e-05 PrevectorResizeNontrivial, 5, 28900, 5.5337, 3.70951e-05, 4.06548e-05, 3.77546e-05 PrevectorResizeTrivial, 5, 90300, 6.12034, 1.34612e-05, 1.36284e-05, 1.35595e-05 RIPEMD160, 5, 440, 5.30861, 0.00228558, 0.00266295, 0.00231056 RollingBloom, 5, 1500000, 3.76308, 4.91852e-07, 5.16104e-07, 4.93168e-07 RpcMempool, 5, 40, 4.50156, 0.0221999, 0.0232148, 0.0222907 SHA1, 5, 570, 5.26881, 0.00173195, 0.00218014, 0.00177544 SHA256, 5, 340, 5.2662, 0.00293822, 0.00338306, 0.00298748 SHA256D64_1024, 5, 7400, 27.3516, 0.000731805, 0.000745226, 0.000739749 SHA256_32b, 5, 4700000, 4.99871, 2.10228e-07, 2.1598e-07, 2.12485e-07 SHA512, 5, 330, 4.93659, 0.00273268, 0.00336214, 0.00298565 SipHash_32b, 5, 40000000, 5.32465, 2.62159e-08, 2.73891e-08, 2.6414e-08 Sleep100ms, 5, 10, 5.00404, 0.100078, 0.100084, 0.100081 Trig, 5, 12000000, 1.15843, 1.92171e-08, 1.95413e-08, 1.92478e-08
Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc
Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc
Differential Revision: https://reviews.bitcoinabc.org/D4398