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 82A3BCFDB for ; Thu, 13 Jun 2013 20:27:05 +0000 (UTC) Received: (qmail 1275 invoked by uid 500); 13 Jun 2013 20:27:05 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 1181 invoked by uid 500); 13 Jun 2013 20:27:05 -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 1173 invoked by uid 99); 13 Jun 2013 20:27:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Jun 2013 20:27:05 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of phil.steitz@gmail.com designates 209.85.192.176 as permitted sender) Received: from [209.85.192.176] (HELO mail-pd0-f176.google.com) (209.85.192.176) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Jun 2013 20:26:58 +0000 Received: by mail-pd0-f176.google.com with SMTP id t12so6878706pdi.21 for ; Thu, 13 Jun 2013 13:26:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=X76DFj7k0Ail1ff5lgn67wRK0NtLUXXgkTZV+wo6ZRk=; b=R4M0Xfun7FbVXHtKX08hNmCOL9f2KpoxTFeURY0R5MkfinNa6pNzM9Zq8psxTpGGx4 +e1yirsVbaY4BPyyCjASyS/py+dH7lPe+Qf1PkmChZs7lpRIyLqqxT+BrUG+iIcc1L1O x2FRrlEwaBeyWCNrEcBRcLGZoubP+7zO4hbTdsBbz7UAqzpTZvW7DtfkvYSfKvia8CF4 wD+2ZEPq4zeKeLE3sWopenV7ClAX/XKMME7E+8VwRHdUPRnpsDNaPEBa1Oimmo4M24Nb xdCX8OOWBHnshwlsIqKCFLjrzKTMwrRGAcX+8n0JApahv+SMHQ9errHdHP4oUBBsOCio N7CA== X-Received: by 10.68.139.33 with SMTP id qv1mr2466193pbb.93.1371155198596; Thu, 13 Jun 2013 13:26:38 -0700 (PDT) Received: from [10.26.70.76] (63-237-194-154.dia.static.qwest.net. [63.237.194.154]) by mx.google.com with ESMTPSA id eq5sm24606297pbc.15.2013.06.13.13.26.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Jun 2013 13:26:37 -0700 (PDT) Message-ID: <51BA2AFE.3080808@gmail.com> Date: Thu, 13 Jun 2013 13:26:38 -0700 From: Phil Steitz User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: Commons Developers List Subject: Re: [LANG] Method to return random byte array? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org On 6/13/13 1:03 AM, Duncan Jones wrote: > Hi, > > A piece of code I write far too often is: > > ====== > public static byte[] getRandomBytes(int length) { > // validate length is non-negative > > byte[] result = new byte[length]; > RANDOM.nextBytes(result); > return result; > } > ====== > > Is there a place for something like this in Commons Lang? Or, better, > does this already exist in another commons project? I would be +1 for adding this (modified to use the configured RandomGenerator) to the RandomDataGenerator class in o.a.c.math.random. The advantage of adding it to there is that that class allows the underlying PRNG to be configured by the user. I am not sure where this little method would fit in [lang]; but it might make sense to add there in the simple form above (with RANDOM static, I assume). Phil > > Duncan > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org