Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to generate random numbers in Java?

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to generate random numbers in Java?

    I know that you have to import Random from the Java utilities and I know how to generate the number when you have certain parameters like generating a number between 5 and 15, but how can you do it if the number has to be one of the following: 0, 0.25, 0.5, 1, 2, or 4. Is there a way to set the parameters to this? Any help is appreciated!! Thank you!!


  2. #2
    Member
    Join Date
    Sep 2013
    Posts
    70
    Thanks
    1
    Thanked 13 Times in 13 Posts

    Default Re: How to generate random numbers in Java?

    I have never done that with randoms. Perhaps you are complicating it more than it should? I see a solution with an Array and a random value with max size of array.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to generate random numbers in Java?

    Put those numbers in an array and randomly choose them from their indices, 0 through 5.

Similar Threads

  1. Generate random numbers between 1 and 52 by passing a seed to Random.
    By Shareefuddin in forum Object Oriented Programming
    Replies: 2
    Last Post: April 22nd, 2013, 09:48 AM
  2. How to use the Random statement to generate a random attack.
    By Shzylo in forum Java Theory & Questions
    Replies: 5
    Last Post: March 3rd, 2013, 07:05 PM
  3. Replies: 1
    Last Post: February 15th, 2013, 08:03 PM
  4. Generate random number in Java
    By waiheng1986 in forum Java Programming Tutorials
    Replies: 1
    Last Post: March 11th, 2012, 12:55 PM
  5. [SOLVED] Java program to generate 10 random integers and then sum computed
    By Lizard in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 14th, 2009, 12:33 PM

Tags for this Thread