Results 1 to 7 of 7
  1. #1
    nothing4me is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Question Simple Java probablitity program?

    Could anyone type up a simple probability program?

    For example...
    a has a chance of being picked .44
    b has .22
    c has .30
    d has .04
    All added equals 1.00

    So, how would I print a string of 50 chars, a through d, with those probabilities/chances?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Could anyone type up a simple probability program?
    yes, you. please don't ask others to do your homework.

    You could create an array of 100 chars and place x 'a' chars in it, y 'b' chars in it, etc... then use the util Random class to randomly select a char and use it.

  3. #3
    nothing4me is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    yes, you. please don't ask others to do your homework.

    You could create an array of 100 chars and place x 'a' chars in it, y 'b' chars in it, etc... then use the util Random class to randomly select a char and use it.
    I already thought of that... I'm sure there's a much more less barbarous way, so I'm asking here. :(

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Nothing barbarous about it. If it works, use it. If it doesn't don't.

    Oh and cross-posting can frustrate anyone who tries to help you only to find out later that the same answer was given hours ago in a cross-posted thread. No one likes wasting their time, especially a volunteer. The polite thing to do would be to not do this, but if you feel that you absolutely must, to at least provide links in both cross-posts to each other.

    sun java forums post

  5. #5
    nothing4me is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default

    If anyone can suggest a more efficient way, please let me know!

    And thanks, Fubarable. But, I need efficiency. :(

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Then tell me how is it inefficient? Have you run it through a profiler and found it to have bottlenecks? What are the bottlenecks then? Just what do you suppose is faster than calling a random method followed by a quick lookup in an array?
    Last edited by Fubarable; 11-12-2008 at 05:27 AM.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Interesting that you chose to concentrate on your little flame war in the other forum, and decided to ignore any constructive discussion in this forum.

Similar Threads

  1. the explanation of output of simple java program
    By amol84 in forum New To Java
    Replies: 1
    Last Post: 11-06-2008, 05:06 PM
  2. Not able to debug simple hello world program
    By amit123solanki in forum New To Java
    Replies: 1
    Last Post: 06-12-2008, 03:41 PM
  3. Peculiarty in code of simple program...
    By Kreuz14 in forum New To Java
    Replies: 4
    Last Post: 01-23-2008, 03:27 AM
  4. help with simple program in java
    By katie in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 08:03 PM
  5. help with simple java program
    By leonard in forum New To Java
    Replies: 3
    Last Post: 07-30-2007, 09:40 AM

Posting Permissions

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