Jump to content

[SOLVED] ~n00b~ Lottery Numbers Script


MasterACE14

Recommended Posts

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");

?>

Link to comment
https://forums.phpfreaks.com/topic/52465-solved-~n00b~-lottery-numbers-script/
Share on other sites

lol, thanks I'm just a noob trying to learn  :P  , 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  :D

 

Regards ACE

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.

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);
?>

woah thorpe, perfect man, Exactly what I want!! and a hell lot simplier! lol.

 

lol, Love the commenting Barand ;D right up their with the pros! ps. Nice Sig.

 

what a team you guys make ;D

 

Keep up the good stuff, PHP Freaks Own the day(so what else is new?  :P )

 

Thanks again mate! Problem solved  ;D

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  :P

 

Thanks Again guys.

 

ACE

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.