Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BB8CB77E4 for ; Mon, 24 Oct 2011 04:52:13 +0000 (UTC) Received: (qmail 17081 invoked by uid 500); 24 Oct 2011 04:52:11 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 16247 invoked by uid 500); 24 Oct 2011 04:52:10 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 16233 invoked by uid 99); 24 Oct 2011 04:52:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Oct 2011 04:52:07 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of ahmed.elmasri@gmail.com designates 209.85.213.171 as permitted sender) Received: from [209.85.213.171] (HELO mail-yx0-f171.google.com) (209.85.213.171) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Oct 2011 04:52:01 +0000 Received: by yxl31 with SMTP id 31so4111802yxl.30 for ; Sun, 23 Oct 2011 21:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=HSY0P4jzd08QVmtxMEYvRrsZ49FLRzf02F+vvWCpqMg=; b=NJuifI52GkHnPI6pFqbn5Z0E0+6yTBzY5eqHPkDq40GNqPC2HcOXBcdic5XVAsUezH 8KzU1LcGHbbNsH4a+r/ZwEJx8d0NO/hZylorHzw0m6IlisR/GpgXhP6AEDUPlxJPIy56 lzNOqXDDxd7B5VqkwMIIRmhnTGTzm+LCGbKRI= MIME-Version: 1.0 Received: by 10.236.181.225 with SMTP id l61mr31952300yhm.131.1319431900483; Sun, 23 Oct 2011 21:51:40 -0700 (PDT) Received: by 10.236.157.68 with HTTP; Sun, 23 Oct 2011 21:51:40 -0700 (PDT) Reply-To: ahmed.elmasri@gmail.com In-Reply-To: <4EA4E73B.1080805@gmail.com> References: <4EA38A25.7000506@gmail.com> <4EA4E73B.1080805@gmail.com> Date: Mon, 24 Oct 2011 00:51:40 -0400 Message-ID: Subject: Re: [math] Re: binomial random generator From: Ahmed Abdeen Hamed To: Commons Users List Content-Type: multipart/alternative; boundary=20cf305639abbbd09f04b0042d16 --20cf305639abbbd09f04b0042d16 Content-Type: text/plain; charset=ISO-8859-1 Hi Phil, Thank you for your response. The answer you provided gave me only half of what I need. The other half is how to get this boolean value with a given probability much the same as nextBonimial? Thanks very much! Ahmed On Mon, Oct 24, 2011 at 12:19 AM, Phil Steitz wrote: > On 10/22/11 8:40 PM, Ahmed Abdeen Hamed wrote: > > Hi Phil, > > > > Thanks very much for your quick response. I am doing some simulations > that > > produce probailities which are in turn must be compared to certains > rates. > > Here is an example of what I am doing: > > > > if (randBinomial.nextBinomial(1, Simulation.MRATE)==1) { > > > > // the condition can be replaced by the following uncommented condition > > > > //randM.nextDouble() < Simulation.M_RATE; > > > > if (gt[i] == 0) { > > > > gt[i] = 1; > > > > } else { > > > > gt[i] = 0; > > > > } > > > > } > > > > Please let me know if I am using Binomial object and its method > correctly. > > As Ted pointed out, you should not be generating values from the > Binomial distribution here. That distribution is for the number of > successes in a given number of Bernoulli trials. The degenerate > case, where the number of trials is 1, can be much more efficiently > handled just generating a random boolean, which can be generated by > a RandomGenerator directly. As Luc pointed out, there are better > PRNGs in [math] than the JDK-supplied generator. To use, for > example, a Well generator, just do > > RandomGenerator gen = new Well19937c(); > > and then > > gen.nextBoolean(); > > to generate (pseudo-)random boolean values. > > Phil > --20cf305639abbbd09f04b0042d16--