commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz" <p...@steitz.com>
Subject Re: Fw: RandomStringUtils Bug
Date Tue, 13 May 2003 07:14:02 GMT
Stephen Colebourne wrote:
> ----- Original Message ----- 
> From: <rs@haenchen.softwarezentrum.de>
> To: <scolebourne@joda.org>
> Sent: Monday, May 12, 2003 3:53 PM
> Subject: RandomStringUtils Bug
> 
> 
> 
>>Hi Stephen,
>>
>>may I suggest to change the Code to the method random:
>>
>>public static String random(int count, char[] set) 
>>{
>>  return random(count, 0, set.length, false, false, set);
>>}
>>
>>The change is not to subtract 1 from set.length. It happens to me
>>that, based on your implementation, the highest char of the array never
>>got chosen.
>>
>>E.g.
>>
>>String s = RandomStringUtils.random(25,"abc123");
>>System.out.println(s);
>>
>>used to produce
>>
>>acaa2bbcb2211a2a2b22a21ab
>>2aac2cc2211b22babbbcc12ab
>>bc11c1aba21caabc1bcbaa1ac
>>
>>You may notice that there is no character '3' in it.
>>
>>After my change I get
>>
>>11222233c2abcbacbbc1ba2cb
>>ba1aaa2c2aa1112bb331c1332
>>32aaa333123312b2baaacacb1
>>
>>
>>Hope this is for use for you.
>>
>>
>>Roman
>>

I have submitted patches making the suggested change and adding a test 
case that fails before the change and succeeds afterwards.

http://issues.apache.org/bugzilla/show_bug.cgi?id=19880

The test case generates 100 6-character strings from a 3-character set 
and verifies that the characters from the set are showing up with 
expected frequency.  It uses a chi-square test, similar to the tests 
that I submitted for RandomUtils here:

http://issues.apache.org/bugzilla/show_bug.cgi?id=19756

>>
>>-- 
>>________________________________________________________________________
>>Roman Seibold, Dipl.-Inform.
>>Haenchen & Partner, Beratungsgesellschaft fuer Wirtschaftsinformatik mbH
>>Calwer Str. 1,  71034 Boeblingen, Germany
>>
>>Roman.Seibold(at)haenchen.softwarezentrum.de
>>http://www.haenchen.softwarezentrum.de
>>Phone: +49 (0)7031 2126 100
>>FAX:   +49 (0)7031 2126 199
>>________________________________________________________________________
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message