[ 
https://issues.apache.org/jira/browse/LUCENE-4148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13395487#comment-13395487
 ] 

Dawid Weiss commented on LUCENE-4148:
-------------------------------------

I didn't check _TestUtil, to be honest -- I think it did have a bug with range 
overflow passed to nextInt (which is not a problem in practice, but was my 
example on how randomized testing can explore unexpected things). 

Anyway, as for randomLongBetween -- here you'd need to be more careful about 
double's representation so simple scaling won't work (there are ranges of 
double that transform to NaNs for example). I am not so strong in numerical 
analysis to be able to prove something is a correct solution to the problem. My 
(naive) take at this would be to calculate the range and then if split into a 
few cases:

1) if it doesn't exceed a positive int, use nextInt()
2) if it doesn't exceed a positive long, use nextLong()
3) if it does exceed positive long, use BigDecimal? :) 

Maybe this can be done faster without keeping the uniform distribution 
requirement so strong (i.e. use a modulo from a combination of two concatenated 
longs as BigDecimal or something like that).
                
> _TestUtil should be able to generate random longs
> -------------------------------------------------
>
>                 Key: LUCENE-4148
>                 URL: https://issues.apache.org/jira/browse/LUCENE-4148
>             Project: Lucene - Java
>          Issue Type: Improvement
>          Components: general/test
>            Reporter: Adrien Grand
>            Priority: Trivial
>
> It would be helpful in TestPackedInts at least, in order to generate random 
> values (as a workaround, we currently generate a random int between 0 and 
> {{min(Integer.MAX_VALUE, PackedInts.maxValue(bitsPerValue)}}). Moreover, it 
> would help to fix {{nextInt}} for large ranges (calling {{nextInt(random, 
> -10, Integer.MAX_VALUE)}} or even {{nextInt(random, 0, Integer.MAX_VALUE)}} 
> currently fails because the range of values is {{> Integer.MAX_VALUE}}.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to