commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gus Power (JIRA)" <>
Subject [jira] [Commented] (LANG-1196) Provide way to set random number generator on RandomStringUtils to enable repeatable test execution
Date Sun, 23 Oct 2016 18:58:58 GMT


Gus Power commented on LANG-1196:

Yes from a thread-safety point of view your patch of just setting the seed on the underlying
random is definitely better. The stock Random.setSeed(seed) method is synchronized and so
shouldn't need an explicit lock. I guess a possible alternative is to pass in a Random but
it there are already plenty of randomX() style methods on there and I didn't want to create

I broke out the Scenario class to better understand what was happening in the random generation.
I wasn't immediately obvious to me that it walks backwards through the character array, shuttling
forward a step if it happens upon a surrogate character and it's at the first element. In
this instance I was trying to determine whether it's a bug to allow odd numbers of characters
when requesting UTF-16 surrogate pairs. The Scenario class passes all the units tests without
change so it should be functionally equivalent to the existing implementation. 

> Provide way to set random number generator on RandomStringUtils to enable repeatable
test execution
> ---------------------------------------------------------------------------------------------------
>                 Key: LANG-1196
>                 URL:
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.4
>         Environment: java version "1.8.0_66"
> Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
> Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
> Linux 4.0.5 #3 SMP Mon Sep 14 12:41:09 BST 2015 x86_64 Intel(R) Core(TM) i7-4710MQ CPU
@ 2.50GHz GenuineIntel GNU/Linux
>            Reporter: Gus Power
>            Priority: Minor
>         Attachments: LANG-1196.patch
> Hi,
> I'm using [Sham |]
to generate realistic looking test data for both parameterized tests and user acceptance testing.
We log the seed that is used for each run so that if there is an issue we can recreate exactly
the same test data. I would also like to use some of the commons-lang RandomStringUtils functionality
but notice that the implementation provides no way of setting the random number generator
to be used.
> {code}private static final Random RANDOM = new Random();{code}
> A way to configure this would be really useful. If there is an alternative way to do
this then that would be great. If you think it's a good idea and it requires a patch I'm happy
to supply one.
> Cheers,
> Gus.

This message was sent by Atlassian JIRA

View raw message