Results 1 to 2 of 2
  1. #1
    bobmiknob is offline Member
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

    Default Help with my first program. Random number gen.

    Ok this is what I am trying to do right now it make a set of random numbers. Kinda like a lotto picker. Two groups one for the first five numbers. One for the second group. I have that all good and well. But the issue is.. Some times they repeat. I'm guessing I need to stick a boolean in there? Here is the code I have.
    Java Code:
    public class lottoo {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		String [] numListOne = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56"};
    
    		String [] numListTwo = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46"};
    		// Find out how many Numbers are in each group.  
    		int oneLength = numListOne.length;
    		int twoLength = numListTwo.length;
    		
    		
    		// This next line will pick 5 random numbers from one group.  And one number from the other group.  Least I hope.
    		int rand1 = (int) (Math.random() * oneLength);
    		int rand2 = (int) (Math.random() * oneLength);
    		int rand3 = (int) (Math.random() * oneLength);
    		int rand4 = (int) (Math.random() * oneLength);
    		int rand5 = (int) (Math.random() * oneLength);
    		int rand6 = (int) (Math.random() * twoLength);
    		
    		
    		
    		
    		
    		// Putting it all together
    		
    		String pharse = numListOne[rand1] + " " + numListOne[rand2] + " " + numListOne[rand3] + " " + numListOne[rand4] + " " +  numListOne[rand5] + " " + numListTwo[rand6];
    		
    		System.out.println("  " + pharse);
    		
    		
    		
    	}
    
    }
    Any help or pointing in the right direction would be great. Thank you for your time.
    Adam
    Last edited by bobmiknob; 09-25-2011 at 12:08 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,251
    Rep Power
    25

    Default Re: Help with my first program. Random number gen.

    Some times they repeat.
    If you want only unique numbers, then either remove the number from the list as it is chosen or keep track of what has been chosen and skip it if chosen again.

Similar Threads

  1. Random Number Algorithm
    By javauserjava in forum New To Java
    Replies: 5
    Last Post: 04-06-2011, 12:32 AM
  2. Random number generator
    By zerwik in forum New To Java
    Replies: 3
    Last Post: 12-26-2010, 12:10 PM
  3. generating random number between 0 and 1
    By sara12345 in forum New To Java
    Replies: 1
    Last Post: 04-17-2010, 07:54 PM
  4. Random number help
    By jgonzalez14 in forum New To Java
    Replies: 5
    Last Post: 09-16-2008, 09:13 AM
  5. Random number
    By jithan in forum Advanced Java
    Replies: 1
    Last Post: 06-13-2008, 01:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •