Win the Lottery

Previous pageNext page

"Generate a winning lottery ticket."

(Random new next: 6) collect: [:n | (n * 49) rounded + 1].


Use Ctrl+D to display an array of numbers for your UK lottery ticket. We haven't actually won the lottery as yet but "Your Mileage May Vary".

Although the above expression may seem complex it is actually quite easy to see what it's doing if you break it down into sub-expressions and you know how the Random class and the #collect: message work. The first sub-expression in brackets creates a new Random object and asks it for the next six random numbers between 0 and 1. The #collect: message is sent to this array of small numbers and runs each one through the following block which converts it into a number between 1 and 50. The end result is an array of numbers between 1 and 50.

Remember, to get back to these experiments just choose Help/First Splash in any Dolphin tool window.