Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A0C4118317 for ; Sun, 27 Dec 2015 11:48:19 +0000 (UTC) Received: (qmail 89264 invoked by uid 500); 27 Dec 2015 11:48:19 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 89109 invoked by uid 500); 27 Dec 2015 11:48:19 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 89097 invoked by uid 99); 27 Dec 2015 11:48:18 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Dec 2015 11:48:18 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 0FD8E18048A for ; Sun, 27 Dec 2015 11:48:18 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=scarlet.be Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id tAxCUVsQuXWe for ; Sun, 27 Dec 2015 11:48:11 +0000 (UTC) Received: from eir.is.scarlet.be (eir.is.scarlet.be [193.74.71.27]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 075B320185 for ; Sun, 27 Dec 2015 11:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scarlet.be; s=scarlet; t=1451216889; bh=aa3rTGmqmmiDaQ6oJjv12o8GOgIGANMDANQXx5RP8IY=; h=MIME-Version:Content-Type:Content-Transfer-Encoding:Date:From:To: Subject:In-Reply-To:References:Message-ID; b=DyQ348A9SuPzApZm7wLJt3kT8wya2DhGqjuF6egBmYd9O6RTz+8MaBzWXlCI+18EK bxXMu38oTeUyA50MsZqqPI2pXMnH1HA/WeWXsFFugZurSgbBisH4N1pq8iVQ4PU1ct 1sHgQ1hf0f/kYq+xkLqaEn+6Bt6ZJo88GddWqonE= Received: from webmail.scarlet.be (meigs.is.scarlet.be [193.74.71.216]) by eir.is.scarlet.be (8.14.9/8.14.9) with ESMTP id tBRBm8qQ029469 for ; Sun, 27 Dec 2015 12:48:09 +0100 X-Scarlet: d=1451216889 c=193.74.71.216 Received: from ip-83-134-186-160.dsl.scarlet.be ([83.134.186.160]) via ip-83-134-186-160.dsl.scarlet.be ([83.134.186.160]) by webmail.scarlet.be with HTTP (HTTP/1.1 POST); Sun, 27 Dec 2015 12:48:08 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 27 Dec 2015 12:48:08 +0100 From: Gilles To: Subject: [Math] "BitsStreamGenerator" as base class for all RNGs (Was: New base class for all RNGs) In-Reply-To: <973d22673ddd25480afb911821dadfd4@scarlet.be> References: <4741114c4f780fd7e503183346ac015c@scarlet.be> <567F1564.8000105@gmail.com> <973d22673ddd25480afb911821dadfd4@scarlet.be> Message-ID: <26356794bf6f08a48ad19be20e792748@scarlet.be> X-Sender: gilles@harfang.homelinux.org User-Agent: Scarlet Webmail X-DCC-scarlet.be-Metrics: eir; whitelist X-Virus-Scanned: clamav-milter 0.98.1-exp at eir X-Virus-Status: Clean Hi. >> [...] >> BitStreamGenerator uses the more standard int next(int bits). Note >> that we have *no* internal direct implementations of >> AbstractRandomGenerator, while BitStreamGenerator has worked very >> nicely as a root for good PRNGs. > > Something implicit in "BitStreamGenerator": the maximum number of > bits is 32 (cf. return type of "next(int)" and the ubiquitous use > of hard-coded "32". > > What about the possibility of using a "long" as a building block > for another family of RNG? > > Gilles > >> >> Therefore, I think for V4 it might actually be best to just drop >> AbstractRandomGenerator. Sorry I did not think of this before >> responding above. >> >> Phil (1) Do all RNG that are going to ever be implemented in CM based on a "int next(int)" method? If not, then we can have a problem as soon as there is another way to provide the random bits. (2) Assuming that we only need int next(int bits) I notice that the source of random bits does indeed creates an "int", say "x", and then truncates it before returning: protected int next(int bits) { // Build "x"... return x >>> 32 - bits; } So, I believe that the actual basis for generating randomness should be a "public abstract int nextInt()" method to be overridden by concrete RNG producers (as "next(int)" currently is): @Override public int nextInt() { // Build "x"... return x; } and the truncation should be performed inside the respective methods that currently call "next(int)". [Which are all in "BitsStreamGenerator".] For example: replace the current public float nextFloat() { return next(23) * 0x1.0p-23f; } by public float nextFloat() { return (nextInt() >>> 9) * 0x1.0p-23f; } And, as a bonus, this will avoid the unnecessary x >>> (32 - 32) operation currently performed when calling "next(32)". OK? If so, I propose to still create a new "BaseRandomGenerator" class that will be different from "BitsStreamGenerator" because of the above changes. This class should be backported to MATH_3_X so that we can deprecate "BitsStreamGenerator" in 3.6. Gilles --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org