random generator optimization for primes
This commit is contained in:
5
helper.c
5
helper.c
@@ -2,7 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
uint32_t rand32() { return (rand() << 16) | (rand() & 0xFFFF); }
|
uint32_t rand32() { return (rand() << 16) | (rand() & 0xFFFF) | 1; }
|
||||||
|
|
||||||
void print_uint128(unsigned __int128 n) {
|
void print_uint128(unsigned __int128 n) {
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
@@ -32,6 +32,9 @@ uint64_t rand64() {
|
|||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
r = (r << 16) | (rand() & 0xFFFF);
|
r = (r << 16) | (rand() & 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Force the bottom bit to 1, this will make all generated primes odd
|
||||||
|
r = r | 1;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user