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
Share on other sites

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

?>

Link to comment
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.