Hi @Nomachine. I am curious about random mode in this code. is that the random totally fully random each keys or it similiar like keyhunt ?
The "random mode" is designed to generate private keys within a specified range using a pseudo-random number generator (PRNG). Specifically, it employs the Xoshiro256plus PRNG, a high-quality random number generator known for its speed.
Int generateRandomPrivateKey(Int minKey, Int range, Xoshiro256plus &rng) {
Int randomPrivateKey((uint64_t)0);
/ Generate random values in chunks of 64 bits using Xoshiro256plus
for (int i = 0; i < NB64BLOCK; ++i) {
uint64_t randVal = rng.next();
randomPrivateKey.ShiftL(64);/ Shift left by 64 bits
randomPrivateKey.Add(randVal);
}
/ Apply modulo operation and add minKey
randomPrivateKey.Mod(&range);
randomPrivateKey.Add(&minKey);
return randomPrivateKey;
}
The random keys are generated within a specific range defined by minKey and maxKey. These values are derived from the puzzle number or the provided range (via the -r argument or -p).
The generateRandomPrivateKey function ensures that the generated keys fall within this range by applying a modulo operation and adding minKey.
while (!matchFound) {
Int currentBatchKey;
if (randomMode) {
/ Generate a random private key within the thread's range using Xoshiro256plus
currentBatchKey = generateRandomPrivateKey(minKey, range, rng);
} else {
/ Sequential mode
if (intGreater(privateKey, threadRangeEnd)) {
break;
}
currentBatchKey.Set(&privateKey);
}
Each thread initializes its own instance of the Xoshiro256plus PRNG with a unique seed. This ensures that the random sequences generated by different threads do not overlap and remain independent of one another.
/ PARRALEL COMPUTING BLOCK
#pragma omp parallel num_threads(numThreads) \
shared(globalComparedCount, globalElapsedTime, mkeysPerSec, matchFound, \
foundPrivateKeyHex, foundPublicKeyHex, lastStatusTime, lastSaveTime, g_progressSaveCount, \
g_threadPrivateKeys)
{
const int threadId = omp_get_thread_num();
/ Initialize Xoshiro256plus PRNG for this thread
Xoshiro256plus rng(std::chrono::steady_clock::now().time_since_epoch().count() + threadId);
Int privateKey = hexToInt(g_threadRanges[threadId].startHex);
const Int threadRangeEnd = hexToInt(g_threadRanges[threadId].endHex);
#pragma omp critical
{
g_threadPrivateKeys[threadId] = padHexTo64(intToHex(privateKey));
}
The keys are distributed uniformly across the range.
Therefore, this process is entirely random, consistent with the approach I always use in all my scripts.