Results 1 to 3 of 3
Thread: Random Lottery Numbers
- 04-29-2011, 02:14 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 5
- Rep Power
- 0
Random Lottery Numbers
This program (not all methods shown) takes the users input of 6 numbers ( 5 numbers and 1 megaball) and compares them with 6 random numbers generated by the computer to see how likely someone is to win the lottery. My problem is with the lotteryPicks() method. Here's the issue I don't know how to create 6 random numbers n amount of times( say 500 )? So ideally it would generate 6 numbers say 12,14,45,32,25,17 and the next time generate 6 new numbers until there's 500 sets of numbers. Also, can you return in a for-loop? Any help would be appreciated!Java Code:import java.util.Random; import java.util.Scanner; class Lottery { private int lotteryNumbers[]; public int [] lotteryPicks() { lotteryNumbers = new int[499]; for (int i = 0; i < lotteryNumbers.length; i++) { lotteryNumbers[i] = (int) (Math.random() * 55) + 1; } return lotteryNumbers; }
- 04-29-2011, 04:16 AM #2
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 3
Why don't you just put another for loop around the for loop you already have?
- 04-29-2011, 06:18 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Is there some reason why you want to generate and return all 500 sets at once rather than calling the method 500 times and doing whatever it is you are doing with the results one at a time? If you *do* want 500 draws returned then Solarsonic is right: make lotteryNumbers a double array and use nested for loops to populate it.
-----------------
Most of these lotteries don't allow duplicates in any particular draw and you are not checking for that. (and the name should reflect what the class models: is this a lottery or a lottery draw?)
Similar Threads
-
Random numbers
By zel2zel in forum AWT / SwingReplies: 3Last Post: 03-09-2011, 06:39 PM -
Is Random() Only For Numbers?
By Salamander in forum New To JavaReplies: 2Last Post: 02-07-2011, 10:02 AM -
How do I generate random numbers in a certain range using the random class?
By frasifrasi in forum New To JavaReplies: 8Last Post: 04-19-2009, 05:50 PM -
random numbers without random class`
By carlos123 in forum New To JavaReplies: 4Last Post: 01-17-2008, 10:44 PM -
random numbers
By carlos123 in forum New To JavaReplies: 1Last Post: 12-22-2007, 02:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks