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

Adrien Grand edited comment on LUCENE-4148 at 6/15/12 3:20 PM:
---------------------------------------------------------------

bq. Try RandomInts from randomizedtesting

Thanks, it fixes the problem for large range of ints, but I would also like to 
be able to generate random longs (> Integer.MAX_VALUE) in a fixed range. For 
{{PackedInts}}, I always need longs between 0 and a power of 2, but I thought 
it would be more useful to add a general-purpose {{long nextLong(Random, long, 
long)}} to {{_TestUtil}}.

Since {{Random.nextLong(long)}} doesn't exist, it would be tempting to 
implement it by ourselves by using the same logic as {{Random.nextInt(int)}} 
(described here: 
http://docs.oracle.com/javase/7/docs/api/java/util/Random.html#nextInt(int) ), 
but I am afraid there would be copyright issues, so we should probably do it 
otherwise ( ? ).

By the way, the code of {{randomIntBetween}} makes me curious, are all values 
as likely when the range of values is {{>= Integer.MAX_VALUE}} (ie. when the 
else block gets executed)?
                
      was (Author: jpountz):
    bq. Try RandomInts from randomizedtesting

Thanks, it fixes the problem for large range of ints, but I would also like to 
be able to generate random longs (> Integer.MAX_VALUE) in a fixed range. For 
{{PackedInts}}, I always need longs between 0 and a power of 2, but I thought 
it would be more useful to add a general-purpose {{long nextLong(Random, long, 
long)}} to {{_TestUtil}}.

Since {{Random.nextLong(long)}} doesn't exist, it would be tempting to 
implement it by ourselves by using the same logic as {{Random.nextInt(int)}}, 
but I am afraid there would be copyright issues, so we should probably do it 
otherwise (?).

By the way, the code of {{randomIntBetween}} makes me curious, are all values 
as likely when the range of values is {{>= Integer.MAX_VALUE}} (ie. when the 
else block gets executed)?
                  
> _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