MasterACE14 Posted May 22, 2007 Share Posted May 22, 2007 I have made a Noobie Lottery Number Script and am wondering how do I make it give unique numbers, instead of 2, 3's , or 4 7's etc. Any Ideas? <?php $a = rand(1,40); $b = rand(1,40); $c = rand(1,40); $d = rand(1,40); $e = rand(1,40); $f = rand(1,40); $g = rand(1,40); $h = rand(1,40); $space = " "; $numbers = "Your Lottery Numbers are "; $result = "$numbers$a$space$b$space$c$space$d$space$e$space$f$space$g$space$h"; echo ("$result"); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted May 22, 2007 Share Posted May 22, 2007 What exactly do you mean? PS; There are much easier ways of doing this. <?php $tmp = ''; for ($i=0;$i<=7;$i++) { $tmp .= rand(0,9).' '; } echo rtrim("Your Lottery Numbers are ".$tmp); ?> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted May 22, 2007 Author Share Posted May 22, 2007 lol, thanks I'm just a noob trying to learn , What I mean is I don't want 2 or more numbers being the same, I want all unique results. --== Ahhh, Hate it when it double posts in error! ==-- Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted May 22, 2007 Author Share Posted May 22, 2007 lol, thanks I'm just a noob trying to learn , What I mean is I don't want 2 or more numbers being the same, I want all unique results. so could you show me how to do that with my script please? I'm gonna have to save your script and break it down later lol Regards ACE Quote Link to comment Share on other sites More sharing options...
trq Posted May 22, 2007 Share Posted May 22, 2007 Ok. <?php // create an array. Same as array(0,1,2,3,4,5,6,7,8,9); $arr = range(1,9); // shuffle the order around. shuffle($arr); // pop the last element off the array so that there is only 8 numbers. array_pop($arr); // print the results. implode() turns the array back into a string with each element seperated by a space. echo "Your Lottery Numbers are " . implode(' ',$arr); ?> Hope this helps. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 22, 2007 Share Posted May 22, 2007 no duplicates: <?php $numbers = range (1,40); // put 40 balls in the bag shuffle ($numbers); // shake the bag $selected = array_slice($numbers,0, ; // take out the top 8 sort($selected); // arrange them in order echo 'Your lottery numbers are: ' . join (', ', $selected); ?> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted May 22, 2007 Author Share Posted May 22, 2007 woah thorpe, perfect man, Exactly what I want!! and a hell lot simplier! lol. lol, Love the commenting Barand right up their with the pros! ps. Nice Sig. what a team you guys make Keep up the good stuff, PHP Freaks Own the day(so what else is new? ) Thanks again mate! Problem solved Quote Link to comment Share on other sites More sharing options...
trq Posted May 22, 2007 Share Posted May 22, 2007 Sorry... didn't see you had edited these to represent 1-40. $a = rand(1,40); They were 1-9 last I looked. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted May 22, 2007 Author Share Posted May 22, 2007 yep, I saw that, my very first post without being edited was stupid lol, choosing 8 numbers, and I wanted them all unique, and it was between 1 and 9, would of done all the numbers except 1 lol Thanks Again guys. ACE Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.