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: Implementing probability in Java

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Implementing probability in Java

    You're given a number between 0 and 1 that corresponds to the probability of an event occurring.
    0.7 is 70%, 0.235 is 23.5%, 0 is 0%, etc.

    Someone tries to perform the event, but the event only has the given probability of occurring. Run the probability, and then if it's true, run the event. Otherwise don't run the event.

    How do you do that?

    All I know how to do is generate random numbers (kind of), but if you have 0.2245 I really don't see how generating random numbers can efficiently perform that probability.....


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

    Default Re: Implementing probability in Java

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    I don't think you've stated the problem well. This statement is particularly confusing:
    Someone tries to perform the event, but the event only has the given probability of occurring. Run the probability, and then if it's true, run the event. Otherwise don't run the event.
    Random numbers or booleans can be used to make logical branching decisions. For example, if a generated random number is greater than a certain amount, then perform this action, otherwise do something else, possibly nothing. That kind of logic can be used to simulate behaviors or results defined by their probability of occurring. You might have heard the term "Monte Carlo Simulation" which is often used to randomly decide outcomes of events. You can search for that term and learn more about it, but that's probably more than you need.

    If you can state the problem better, perhaps using an example of what you need to do or by stating the actual problem exactly as it was given to you, we might be more helpful.

    Edit: Focusing on your last statement,
    if you have 0.2245 I really don't see how generating random numbers can efficiently perform that probability
    The chance or probability that a uniformly distributed randomly generated number between 0 and 1 is less than or equal to 0.2245 is 22.45%.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    PushBilly (June 7th, 2014)

  4. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Implementing probability in Java

    Quote Originally Posted by GregBrannon View Post
    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Edit: Focusing on your last statement,

    The chance or probability that a uniformly distributed randomly generated number between 0 and 1 is less than or equal to 0.2245 is 22.45%.
    That does it right there! Thanks!

Similar Threads

  1. Dice Rolling Probability - How Do I Start It Off?
    By iAce in forum Java Theory & Questions
    Replies: 11
    Last Post: December 16th, 2012, 10:01 PM
  2. Looking for help with java probability assignment.
    By Hasurat in forum Algorithms & Recursion
    Replies: 2
    Last Post: November 5th, 2012, 09:17 PM
  3. Need help with probability assignment
    By tai8 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 13th, 2012, 03:23 PM
  4. random uniform distribution with probability assignment
    By blascobz in forum Object Oriented Programming
    Replies: 0
    Last Post: February 28th, 2011, 09:16 AM
  5. Finding frequency and probability of characters in a string
    By Aberforth in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 31st, 2010, 02:02 AM