A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Is this a good probability formula?

  1. #1
    Senior Member ceglia's Avatar
    Join Date
    Jan 2003
    Location
    Los Angeles
    Posts
    262

    Is this a good probability formula?

    hey guys,

    had a quick question about probability. let's say i have a character X, and there is a 30% probability that he will die when a particular event takes place.

    I need to come up with a formula that determines whether or not X dies based on the 30% probability.

    Here's what I have:

    Code:
    var randNum:Number = Math.random()*100;
    if (randNum > 30) {
    trace("Character X lives");
    } else {
    trace("Character X dies");
    }
    It works, but I wanted to know if there was a better or other method out there.

    Thanks.

  2. #2
    Senior Member axcho's Avatar
    Join Date
    Jun 2006
    Posts
    113
    Well, you don't have to multiply Math.random() by 100. You can just go like
    Code:
    if (Math.random() > 0.3) {
    Other than that, I don't know. What do you mean by "better"? Do you want something more efficient, or more realistic, or something?

  3. #3
    Senior Member ceglia's Avatar
    Join Date
    Jan 2003
    Location
    Los Angeles
    Posts
    262
    I guess what I meant by better was, is there some kind of "best practice" script that everyone is using?

    It seems like the kind of thing that would come up a lot, especially in game development. for example, character X attacks character Y, and because of character X's dexterity or strength or whatever, the probability of X hitting Y is 30%. is character X's attack successful?

    I figured there was some sort of established method.

    thanks for your feedback.
    Last edited by ceglia; 10-21-2006 at 04:27 PM.

  4. #4
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    your method is OK, however flash's random is far from a good random.

    you can get as complex as you can imagine with probabilty, but if it is not that important i would stick with your current method.

    zlatan
    New sig soon

  5. #5
    Senior Member ceglia's Avatar
    Join Date
    Jan 2003
    Location
    Los Angeles
    Posts
    262
    ok, thanks for the reply.

  6. #6
    Bacon-wrapped closures Nialsh's Avatar
    Join Date
    Dec 2003
    Location
    Houston!
    Posts
    338
    dudeqwerty: are you just saying that all artificial computer randoms are bad or are you talking about Flash's specifically?

  7. #7
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    depends on what kind of computer or language you are talking about.

    As flash is written in C, im guessing that they wrote they're own random function for ActionScript to use, so if you are using C's random it will be more "random" than flash's (or any other lass powerful language's) random.

    looking at wikipedia's atricles on various methods computers generate random numbers will help clear things up a little: 1, 2, 3
    New sig soon

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center