mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 14:30:36 +00:00
added tool to find xorshift parameters
This commit is contained in:
parent
7f0bdda536
commit
31458c0f56
1 changed files with 34 additions and 0 deletions
34
tools/xorshift.c
Normal file
34
tools/xorshift.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
Exhaustive search of xorshift parameters
|
||||
|
||||
Copyright 2025 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 2)
|
||||
return 1;
|
||||
int bits = atoi(argv[1]);
|
||||
int mask = (1 << bits) - 1;
|
||||
int seed = 1;
|
||||
for (int a = 1; a < bits; ++a) {
|
||||
for (int b = 1; b < bits; ++b) {
|
||||
for (int c = 1; c < bits; ++c) {
|
||||
int good = 1;
|
||||
for (int y = seed, i = mask; good && i; --i) {
|
||||
y ^= y << a;
|
||||
y &= mask;
|
||||
y ^= y >> b;
|
||||
y ^= y << c;
|
||||
y &= mask;
|
||||
good &= (i == 1) == (y == seed);
|
||||
}
|
||||
if (good)
|
||||
printf("%d %d %d\n", a, b, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue