On 13 June 2013 21:26, Phil Steitz wrote:
> 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.
That looks like a good place to put it. I'll submit a patch to that project.
> 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).
Indeed, I had assumed any addition to [lang] would just use a standard
source of randomness (i.e. a static Random or SecureRandom instance).
However, I'm struggling to see an existing class that could
accommodate the functionality and creating a new "RandomUtils" class
feels a bit heavyweight, unless others can think of additional methods
that would be useful.
Duncan
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]