0

Update
Thanks to the comment by @Gerry Myerson. Now I understand it is a question on Linear Congruential Generator(LCG). I have done some search on this topic and find this answer. Although it does not answer this question directly, it did actually solve my problem. This question could be closed or anyone can post an proper answer to this question (I am not sure if it exists).

Thank you for everyone who have commented!

Question
For a function $f(x)=ax+b \mod 2^{n}$, if we take any number as the first input and apply function recursively, it generates a sequence.
e.g. let $n=4,a=3,b=1,k=5$
$f^1(k)=5*3+1\mod16=0$
$f^2(k)=0*3+1\mod16=1$
$f^3(k)=1*3+1\mod16=4$
$f^4(k)=4*3+1\mod16=13$
$f^5(k)=13*3+1\mod16=8$
$f^6(k)=8*3+1\mod16=9$
$f^7(k)=9*3+1\mod16=12$
$f^8(k)=12*3+1\mod16=5$

Because of the modulo, it will eventually enters a loop. In this case $f^8(5)=5$ which means the loop size is 8. I want to know if there is a way to decide when $a$, $b$ and $n$ is big other than to calculate them one by one.

Some contexts
This question comes from a pseudo random generation function from a library of C. The random number is as follows: $$ state[i+1] = a*state[i]+b \mod{2^{32}} $$ $$ rng=state[i] \mod{2^{31}} $$ My instinct is that this could be answered by field theory because if we remove the "$+b$" in that function: $$ state[i+1] = a*state[i] \mod{2^{32}} $$ Then the question is similar to "Is $a$ a generator of the field". But (@Thomas Andrews) reminds me that modulo of $2^{32}$ is not a field because not every element has a inverse.
So I am stuck here. I don't even know which key word should I search.

Original Question
For a Finite Field $F(2^{32})$ and a function $f(x)=ax+b$, where $a, b\in F$. How do we decide if $f(x)$ is a generator function of the field $F$?

Jin.J
  • 109
  • 3
  • 4
    The integers modulo $2^{32}$ are not a field. There is a field of size $2^{32},$ but it is not the integers modulo $2^{32}.$ – Thomas Andrews Jan 11 '23 at 08:41
  • Thank you for replying! So I did actually misused some terms here. I will try to edit my question. Could you please give some suggestions to help me edit if you understand my question? – Jin.J Jan 12 '23 at 05:06

1 Answers1

0

I feel like your question is "is $f: F\to F$ surjective?". (If that is not your question then you can ignore this answer.)

Then there are two cases:

  • if $a=0$, then $f$ is (clearly) a constant function;
  • if $a\neq 0$, then $f$ is bijective: its inverse is $g(x)=a^{-1}(x-b)$, which is well-defined since $F$ is a field, so any non-zero $a$ is invertible.
Captain Lama
  • 27,658
  • Thank you for your answer! I did not describe my question very well. My question is actually: Can $f^{n}(k)$, $0<n<=2^{32}$ fill up every number from 0 to $2^{32}$, and if not, how many different numbers can it generate before it enters a loop? – Jin.J Jan 12 '23 at 05:05
  • 2
    You are asking for the period of an inhomogeneous linear congruential generator. This has probably been asked and answered on this site in the past (probably many times). I recommend you do a search for earlier questions about this. – Gerry Myerson Jan 12 '23 at 06:02