Results 1 to 3 of 3
  1. #1
    ErtanTaboo is offline Member
    Join Date
    Jun 2015
    Posts
    14
    Rep Power
    0

    Default Can I get a random number , between two randoms?

    Hello guys , i need to know if i could get a random number between two randoms ?
    Java Code:
                            Random generator = new Random();
                            int generator1 = generator.nextInt(7);
    
                              //if generator1 =5;
                            
                            Random randomIndex = new Random();
                            int randomIndex1 = randomIndex .nextInt(8);
    
                              //if randomIndex1 =3;
                           
                            Random randomBetween = new Random();
                                int randomBetween1 = //I need randomBetween1 to be 5 or 3

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Can I get a random number , between two randoms?

    get a random number between two randoms ?
    Use the difference between the two numbers as the range to generate a random number then add the lower number to move it to between the low and high number
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Can I get a random number , between two randoms?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Random number
    By Hawks in forum New To Java
    Replies: 5
    Last Post: 04-30-2013, 07:05 PM
  2. Random number
    By _Chip in forum New To Java
    Replies: 4
    Last Post: 11-03-2012, 07:06 PM
  3. Problem with randoms
    By Urgle in forum New To Java
    Replies: 9
    Last Post: 11-05-2008, 03:55 AM
  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
  •