Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A4170200828 for ; Fri, 13 May 2016 15:27:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A2ABD160A16; Fri, 13 May 2016 13:27:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F38261602BE for ; Fri, 13 May 2016 15:27:13 +0200 (CEST) Received: (qmail 55476 invoked by uid 500); 13 May 2016 13:27:13 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 55442 invoked by uid 99); 13 May 2016 13:27:13 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 May 2016 13:27:13 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id E2D5F2C14F8 for ; Fri, 13 May 2016 13:27:12 +0000 (UTC) Date: Fri, 13 May 2016 13:27:12 +0000 (UTC) From: "Gilles (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (MATH-1341) "RandomDataGenerator" is brittle MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 13 May 2016 13:27:14 -0000 [ https://issues.apache.org/jira/browse/MATH-1341?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Gilles updated MATH-1341: ------------------------- Attachment: RandomUtils.java I attached a new {{RandomUtils}} class which I propose as a replacement for {{RandomDataGenerator}}. Having removed all methods that are _trivial_ syntactic sugar for the sampler API in {{o.a.c.m.distribution}}, the number of lines in {{RandomUtils}} is ~60% of the old {{RandomDataGenerator}}. The "nextSecureXxx" methods were also removed as most were identical to their "non-secure" counterpart, except for the underlying RNG (secure vs not). In {{RandomUtils}}, secure versions are thus "automatically" achieved by passing a secure RNG to the class's constructor. Methods {{nextHexString}} and {{nextSecureHexString}} were different in that the latter uses a {{MessageDigest}} object in its processing. The two codes were merged in a single method and a boolean argument selects one or the other behaviour. {{RandomUtils}} also obsoletes class {{RandomGeneratorFactory}} whose functionality is replaced by the following factory method: {noformat} public static UniformRandomProvider asUniformRandomProvider(final Random rng) { // .... } {noformat} Old "features" intentionally left out: * Lazy initialization (if you don't need the RNG, you don't need an instance of this class) * Reseeding of the RNG (if necessary - although a bad idea - the caller can hold a reference to the {{Random}} object being wrapped, and call "setSeed" on it) Please have a look, and let me know of any functionality I may have missed to port to the new class. > "RandomDataGenerator" is brittle > -------------------------------- > > Key: MATH-1341 > URL: https://issues.apache.org/jira/browse/MATH-1341 > Project: Commons Math > Issue Type: Bug > Reporter: Gilles > Priority: Minor > Labels: API, cleanup, deprecation, thread-safety > Fix For: 4.0 > > Attachments: RandomUtils.java > > > Class {{RandomDataGenerator}} can easily be misused as it advertizes a method to access its internal RNG (which is _not_ thread-safe). > The class is also a mixed bag of "data generators" that are either "secure" or not. > Moreover it uses the "lazy initialization" pattern (for the RNG instance) solely because of this duality; otherwise users that need one or the other form of data generation will obviously always use the RNG since all data generation methods need it. > This entails also a performance hit (albeit tiny) as each call checks whether the RNG has been initialized already. > The clean solution would be to separate the two types of data generation (secure vs not) into different classes. -- This message was sent by Atlassian JIRA (v6.3.4#6332)