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 6 of 6

Thread: Getting a random Yes Or No

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

    Default Getting a random Yes Or No

    Hi Im very new to java and was thinking about a app for android. My idea is to very simply generate a yes or no answer for a question inputted and make it show. I have looked around and i see that you can get random numbers with java.util.Random.

    My idea would be something like this as i have previously used lua quite some time ago

    if random >5
    then print yes

    else
    print no

    any help will be appreciated


    Thanks


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Getting a random Yes Or No

    Hi Mangos64,

    Yes you can do this with Java, using the java.util.Random class:

    Random (Java Platform SE 6)

    Your logic is sound, this will work perfectly in java as well as lua.


    Chris

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Getting a random Yes Or No

    Thanks

    Also would it be possible to shake the phone using the accelerometer and use this to make it say the answer


    Some thing like this

    If accelerometer >5g
    print (random_yes_or_no) (question)


    if so how would I do this

    Thanks once again

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Getting a random Yes Or No

    Yes you can do that too.
    Very much like you describe in the pseudo code.
    Perhaps you might work on displaying a message first, then work on displaying that message when the phone shakes.
    Take it one step at a time. Post questions if you get stuck. Include error messages with the code

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Getting a random Yes Or No

    The Random class can also generate random booleans which better map to yes/no.
    Improving the world one idiot at a time!

  6. #6
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Getting a random Yes Or No

    Sounds good i will be reading up on books first and then try that thanks.

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

Tags for this Thread