This commit is contained in:
2026-04-14 09:01:39 +02:00
parent bcb399deba
commit de292aba25

View File

@@ -37,7 +37,6 @@ uint64_t rand64() {
// Stitch two 64-bit random numbers into a 128-bit number // Stitch two 64-bit random numbers into a 128-bit number
unsigned __int128 generate_stitched_128() { unsigned __int128 generate_stitched_128() {
// Make sure to seed rand() in your main function with srand(time(NULL))
uint64_t top_half = rand64(); uint64_t top_half = rand64();
uint64_t bottom_half = rand64(); uint64_t bottom_half = rand64();
@@ -48,10 +47,9 @@ unsigned __int128 generate_stitched_128() {
} }
unsigned __int128 generate_prime_candidate() { unsigned __int128 generate_prime_candidate() {
// 1. Get the raw random bytes
unsigned __int128 candidate = generate_stitched_128(); unsigned __int128 candidate = generate_stitched_128();
// 2. Force the bottom bit to 1 (Ensures it is odd) // Force the bottom bit to 1, this will make all generated primes odd
candidate = candidate | 1; candidate = candidate | 1;
// 3. Force the top bit to 1 (Ensures it is a full 128-bit number) // 3. Force the top bit to 1 (Ensures it is a full 128-bit number)