Tandem Posted October 6, 2006 Share Posted October 6, 2006 Hi,I have come to a situation where i need 2 variables that are both numbers, and both generated with rand(), and they both have to be different on every occasion.For example if they both equal 6, then that is bad.At the moment due to lack of knowledge of what to do properly, i am using the following code:[code]<?phpif (!empty($something)){$var1 = rand(1,52);$var2 = rand(1,52);if ($var1 == $var2){$var1 = rand(1,52);$var2 = rand(1,52);}if ($var1 == $var2){$var1 = rand(1,52);$var2 = rand(1,52);}if ($var1 == $var2){$var1 = rand(1,52);$var2 = rand(1,52);}}?>[/code]The chances of them still being the same after this is pretty small, but still possible. What is the proper way to solve my problem?Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/23228-i-need-2-different-variables/ Share on other sites More sharing options...
Tandem Posted October 6, 2006 Author Share Posted October 6, 2006 nvm, i realised to use a while loop. Link to comment https://forums.phpfreaks.com/topic/23228-i-need-2-different-variables/#findComment-105301 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.