MyBB Community Forums

Full Version: Issues with rand(); in template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In my code I have a var that generates a random number between 1-12

$randomnumber = rand(1,12);

I then display {$randomnumber} in a template that shows this random number which may show 4 for example.

I then do 

if( $mybb->input['bet'] == 'high' )
   
{

error($randomnumber);

}

Which shows a completely different number to the one showing in the template. I believe this is because the function is run by the template and then rerun in the script. As when I run the action bet=high it displays a different number to the one in the template is there any way to avoid this?
"input bet" is in a form? If yes, you could put the random number in an hidden input and then recall it with
$mybb->input['my_hidden_input']
(2016-03-09, 01:09 PM)Paradigm Wrote: [ -> ]In my code I have a var that generates a random number between 1-12

$randomnumber = rand(1,12);

I then display {$randomnumber} in a template that shows this random number which may show 4 for example.

I then do 

if( $mybb->input['bet'] == 'high' )
   
{

error($randomnumber);

}

Which shows a completely different number to the one showing in the template. I believe this is because the function is run by the template and then rerun in the script. As when I run the action bet=high it displays a different number to the one in the template is there any way to avoid this?

Can you show me the full code?
PM me in case you do not wish to make it public.
Solved.