Not sure I understand your issue, let me go through it as I understand it.
You have this $X-variable, that goes through three functions and it is updated on all of these.
Not sure why you use functions but you might have a reason, or are just using word 'function' to mention it as a stage of where the $X is handled?
But according to your explanation of issue you have these,
1. If $X > 0, then >> throw a link for user to be able to declare $X again.
2. Then you have a phase where $X = rand(0,1000)?? What happens to whatever user declares?
3. ??? I lost my thought, I re-read your text and didn't find a third phase
I re-read and re-read your explanation but sorry I have some trouble understanding what you want
or is this what you want to know::
Then I want to be able to display the result of the three functions and $X on the front page.
As you mentioned also after this sentence, if the results are set by refreshing the page several times, you can use SESSION to store the value between refresh.
Or use some kind of database. In any case, if you you want a result that happens between several refreshes of page in different instances, you need to store the results in between when they meet your acceptance criteria.
When typing explanation, try pressing that enter a few times, it was really hard to read
