-
Senior Member
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.
-
Senior Member
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?
-
Senior Member
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.
-
Senior Member
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
-
Senior Member
ok, thanks for the reply.
-
Bacon-wrapped closures
dudeqwerty: are you just saying that all artificial computer randoms are bad or are you talking about Flash's specifically?
-
Senior Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|