commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <phil.ste...@gmail.com>
Subject Re: [LANG] Method to return random byte array?
Date Thu, 13 Jun 2013 20:26:38 GMT
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


Mime
View raw message