Error message

Notice: Array to string conversion in eval() (line 26 of /mnt/lvm2/siliconmeadow.net/httpdocs/modules/php/php.module(80) : eval()'d code).

Lottery Number Generator (6 - 49)

Code from a while back

I must have written this about five years ago, when I wanted to break away from using only Dreamweaver behaviours to produce the clever stuff in PHP.

With our new content management system, I've discovered that I can throw in snippets of PHP code that will execute. The best of both worlds, it would seem to me!

So below you will find six numbers to play in a Lotto 6-59 game (like the UK's National Lottery).

Tonight's winning numbers are....

Ball Number 1 is 9.

Ball Number 2 is 43.

Ball Number 3 is 10.

Ball Number 4 is 51.

Ball Number 5 is 59.

Ball Number 6 is 32.

Everytime you visit this page, you will have a different set of numbers. Don't believe me? Click here to refresh the page.

The code that generates this looks like this (with comments to help):

<?php
// initialise array
Array = array ();

// fill the array from 1 to 49, emulating the filling of the bin
for($count 1$count <= 49$count++){
  
array_push($lottoNum,$count);
}

/**
 * First, we shuffle. Take the new first number and then
 * take it out of the array with array_shift set the bin
 * spinning again with the shuffle function.
 *
 * Ultimately, we become millionaires. I get 10% of all
 * winnings if you use this code and win. ;-)
 */

for($index 1$index <= 6$index++){
  
shuffle($lottoNum);
  print(
"<p>Ball Number <strong>$index</strong> is <strong>$</strong>. /p>
"
);
  
array_shift($lottoNum);
}
?>

My friend Greg and I were examining the entertaining conversations regarding the shuffle() function at http://www.php.net/manual/en/function.shuffle.php and Greg pointed out that my bit of code here doesn't quite satisfy the Fisher Yates shuffle requirements, but what did they know? Neither of them ever won the lottery, did they?

27 June 2008

I thought I'd better do a version for the EuroMillions:

EuroMillions example

Number 1 is 8.

Number 2 is 31.

Number 3 is 35.

Number 4 is 6.

Number 5 is 10.

Lucky Star 1 is 10.

Lucky Star 2 is 2.

Comments

A friend just pointed out while I had the web applications caching turned on the numbers didn't change. For the time being, I've disabled the caching, just so I can show off.

My favorite book is "Captain Underpants." http://www.ebook-search-queen.com/ebook/Capt/Captain+Underpants.all.html People should enjoy reading "Captain Underpants" because people have funny names, flip-o-ramas and hilarious jokes. Check it out and enjoy.

I think it's important that everyone have a favourite book. I'm very glad that you found yours.

Thanks alot for this little snippet. Very helpful for my project.

I WON 13 MILLION DOLLARS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 So did I!!!!!!!

Thank you Richard Sheppard for the information,I have to get started on essaysontime ans these Lottery Number Generator are of great help anyways,Keep on posting more of such articles with us.

The generation of lottery number which result for the perfect working. The way such code used it bring the perfect result. The process of getting something form scheme noted. The desire for the essay making allow us for the superіor essay wrіtіng as it found the final result for the people.

Quite Now I’m appreciating efforts you will designed to present the data. Individual right I stabled onto was beneficial to question I was first looking for forever. At this time follow the check cashing With thanks a whole lot.

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><p><img><blockquote><h1><h2><h3><h4><h5><h6>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.
 


 The Right Way