Return-Path: william@bourbon.usc.edu
Delivery-Date: Tue Nov 7 09:20:59 2006
X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on merlot.usc.edu
X-Spam-Level:
X-Spam-Status: No, score=-3.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,
NO_REAL_NAME autolearn=ham version=3.1.3
Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75])
by merlot.usc.edu (8.13.5/8.13.5) with ESMTP id kA7HKxbv022575
for ; Tue, 7 Nov 2006 09:20:59 -0800
Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1])
by bourbon.usc.edu (8.13.5/8.13.5) with ESMTP id kA7HH2Vi002209
for ; Tue, 7 Nov 2006 09:17:02 -0800
Message-Id: <200611071717.kA7HH2Vi002209@bourbon.usc.edu>
To: cs551@merlot.usc.edu
Subject: Re: Probability question
Date: Tue, 07 Nov 2006 09:17:02 -0800
From: william@bourbon.usc.edu
Someone wrote:
> Could you please explain what positive probability is and how to
> calculate it (can we use rand() function)?
The spec didn't use the term "positivie probability".
Let's say you have a probability p=0.2 and you want to flip
coins with this probability. What would you do? If drand48()
returns a real value between 0 and 1 with a uniform
distribution, then you can do:
if (drand48() < 0.2) {
return "positive";
} else {
return "negative";
}
Then 20% of the time, this will return "positive" and 80% of
the time, this will return "negative", which is what you want.
By the way, do you use rand(). Use srand48() and drand48()
or lrand48() instead.
--
Bill Cheng // bill.cheng@usc.edu