Znalazłem kod:
https://en.wikipedia.org/wiki/Xorshift
struct xorshift64_state {
uint64_t a;
};
uint64_t xorshift64(struct xorshift64_state *state)
{
uint64_t x = state->a;
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
return state->a = x;
}
I uruchomiłem go tak:
uint64_t a = 555;
uint64_t xorshift64(void)
{
uint64_t x = a;
x ^= x << 13;
x ^= x >> 7;
x ^= x << 17;
return a = x;
}
int main()
{
uint64_t result = 0;
while (true)
{
result = xorshift64();
//std::cout << result << "\n";
}
}
Nie wiem jak uruchomić oryginalny kod. Co to znaczy, że funkcja przyjmuje jako argument struct xorshift64_state *state
? Co to jest *state
? Co ona właściwie przyjmuje jako argument? Co robi state->a
? Przypisuje wartość state
do a
? Jeśli tak to po co jest to robione w dwóch miejscach kodu? state->a
jest używane raczej jakby było jedną zmienną zapisaną w osobliwy sposób.